mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
Model类增加toCollection方法 用于转换数据集对象
This commit is contained in:
@@ -13,6 +13,7 @@ namespace think;
|
|||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use think\Cache;
|
use think\Cache;
|
||||||
|
use think\Collection;
|
||||||
use think\Config;
|
use think\Config;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
use think\db\Query;
|
use think\db\Query;
|
||||||
@@ -565,6 +566,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return json_encode($this->toArray(), $options);
|
return json_encode($this->toArray(), $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换当前模型数据集为数据集对象
|
||||||
|
* @access public
|
||||||
|
* @param array|Collection $collection 数据集
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function toCollection($collection)
|
||||||
|
{
|
||||||
|
return new Collection($collection);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取模型对象的主键
|
* 获取模型对象的主键
|
||||||
* @access public
|
* @access public
|
||||||
@@ -1200,6 +1212,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @access public
|
* @access public
|
||||||
* @param array $resultSet 数据集
|
* @param array $resultSet 数据集
|
||||||
* @param string $relation 关联名
|
* @param string $relation 关联名
|
||||||
|
* @param string $class 数据集对象名 为空表示数组
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function eagerlyResultSet(&$resultSet, $relation, $class = '')
|
public function eagerlyResultSet(&$resultSet, $relation, $class = '')
|
||||||
@@ -1224,6 +1237,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @access public
|
* @access public
|
||||||
* @param Model $result 数据对象
|
* @param Model $result 数据对象
|
||||||
* @param string $relation 关联名
|
* @param string $relation 关联名
|
||||||
|
* @param string $class 数据集对象名 为空表示数组
|
||||||
* @return Model
|
* @return Model
|
||||||
*/
|
*/
|
||||||
public function eagerlyResult(&$result, $relation, $class = '')
|
public function eagerlyResult(&$result, $relation, $class = '')
|
||||||
@@ -1252,7 +1266,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @param string $localKey 关联主键
|
* @param string $localKey 关联主键
|
||||||
* @param array $alias 别名定义
|
* @param array $alias 别名定义
|
||||||
* @param string $joinType JOIN类型
|
* @param string $joinType JOIN类型
|
||||||
* @return Relation
|
* @return HasOne
|
||||||
*/
|
*/
|
||||||
public function hasOne($model, $foreignKey = '', $localKey = '', $alias = [], $joinType = 'INNER')
|
public function hasOne($model, $foreignKey = '', $localKey = '', $alias = [], $joinType = 'INNER')
|
||||||
{
|
{
|
||||||
@@ -1271,7 +1285,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @param string $otherKey 关联主键
|
* @param string $otherKey 关联主键
|
||||||
* @param array $alias 别名定义
|
* @param array $alias 别名定义
|
||||||
* @param string $joinType JOIN类型
|
* @param string $joinType JOIN类型
|
||||||
* @return Relation
|
* @return BelongsTo
|
||||||
*/
|
*/
|
||||||
public function belongsTo($model, $foreignKey = '', $otherKey = '', $alias = [], $joinType = 'INNER')
|
public function belongsTo($model, $foreignKey = '', $otherKey = '', $alias = [], $joinType = 'INNER')
|
||||||
{
|
{
|
||||||
@@ -1289,7 +1303,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @param string $foreignKey 关联外键
|
* @param string $foreignKey 关联外键
|
||||||
* @param string $localKey 关联主键
|
* @param string $localKey 关联主键
|
||||||
* @param array $alias 别名定义
|
* @param array $alias 别名定义
|
||||||
* @return Relation
|
* @return HasMany
|
||||||
*/
|
*/
|
||||||
public function hasMany($model, $foreignKey = '', $localKey = '', $alias = [])
|
public function hasMany($model, $foreignKey = '', $localKey = '', $alias = [])
|
||||||
{
|
{
|
||||||
@@ -1309,7 +1323,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @param string $throughKey 关联外键
|
* @param string $throughKey 关联外键
|
||||||
* @param string $localKey 关联主键
|
* @param string $localKey 关联主键
|
||||||
* @param array $alias 别名定义
|
* @param array $alias 别名定义
|
||||||
* @return Relation
|
* @return HasManyThrough
|
||||||
*/
|
*/
|
||||||
public function hasManyThrough($model, $through, $foreignKey = '', $throughKey = '', $localKey = '', $alias = [])
|
public function hasManyThrough($model, $through, $foreignKey = '', $throughKey = '', $localKey = '', $alias = [])
|
||||||
{
|
{
|
||||||
@@ -1331,7 +1345,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @param string $foreignKey 关联外键
|
* @param string $foreignKey 关联外键
|
||||||
* @param string $localKey 当前模型关联键
|
* @param string $localKey 当前模型关联键
|
||||||
* @param array $alias 别名定义
|
* @param array $alias 别名定义
|
||||||
* @return Relation
|
* @return BelongsToMany
|
||||||
*/
|
*/
|
||||||
public function belongsToMany($model, $table = '', $foreignKey = '', $localKey = '', $alias = [])
|
public function belongsToMany($model, $table = '', $foreignKey = '', $localKey = '', $alias = [])
|
||||||
{
|
{
|
||||||
@@ -1347,10 +1361,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
/**
|
/**
|
||||||
* MORPH MANY 关联定义
|
* MORPH MANY 关联定义
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $model 模型名
|
* @param string $model 模型名
|
||||||
* @param string|array $morph 多态字段信息
|
* @param string|array $morph 多态字段信息
|
||||||
* @param string $type 多态类型
|
* @param string $type 多态类型
|
||||||
* @return Relation
|
* @return MorphMany
|
||||||
*/
|
*/
|
||||||
public function morphMany($model, $morph = null, $type = '')
|
public function morphMany($model, $morph = null, $type = '')
|
||||||
{
|
{
|
||||||
@@ -1375,7 +1389,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
* @access public
|
* @access public
|
||||||
* @param string|array $morph 多态字段信息
|
* @param string|array $morph 多态字段信息
|
||||||
* @param array $alias 多态别名定义
|
* @param array $alias 多态别名定义
|
||||||
* @return Relation
|
* @return MorphTo
|
||||||
*/
|
*/
|
||||||
public function morphTo($morph = null, $alias = [])
|
public function morphTo($morph = null, $alias = [])
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user