diff --git a/library/think/Model.php b/library/think/Model.php index 0848a108..a1523914 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1261,10 +1261,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param array $resultSet 数据集 * @param string $relation 关联名 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return array */ - public function eagerlyResultSet(&$resultSet, $relation, $class = '', $count = false) + public function eagerlyResultSet(&$resultSet, $relation, $class = '') { $relations = is_string($relation) ? explode(',', $relation) : $relation; foreach ($relations as $key => $relation) { @@ -1278,7 +1277,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess list($relation, $subRelation) = explode('.', $relation); } $relation = Loader::parseName($relation, 1, false); - $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class, $count); + $this->$relation()->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $class); } } @@ -1288,10 +1287,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @param Model $result 数据对象 * @param string $relation 关联名 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return Model */ - public function eagerlyResult(&$result, $relation, $class = '', $count = false) + public function eagerlyResult(&$result, $relation, $class = '') { $relations = is_string($relation) ? explode(',', $relation) : $relation; @@ -1306,7 +1304,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess list($relation, $subRelation) = explode('.', $relation); } $relation = Loader::parseName($relation, 1, false); - $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class, $count); + $this->$relation()->eagerlyResult($result, $relation, $subRelation, $closure, $class); } } diff --git a/library/think/db/Query.php b/library/think/db/Query.php index 79a30eb7..116b7070 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1620,11 +1620,10 @@ class Query /** * 设置关联查询JOIN预查询 * @access public - * @param string|array $with 关联方法名称 - * @param bool $count 是否统计 + * @param string|array $with 关联方法名称 * @return $this */ - public function with($with, $count = false) + public function with($with) { if (empty($with)) { return $this; @@ -1663,8 +1662,7 @@ class Query } } $this->via(); - $this->options['with'] = $with; - $this->options['count'] = $count; + $this->options['with'] = $with; return $this; } @@ -2019,7 +2017,7 @@ class Query } if (!empty($options['with'])) { // 预载入 - $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : '', !empty($options['count']) ? true : false); + $result->eagerlyResultSet($resultSet, $options['with'], is_object($resultSet) ? get_class($resultSet) : ''); } } // 模型数据集转换 @@ -2115,7 +2113,7 @@ class Query } // 预载入查询 if (!empty($options['with'])) { - $data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : '', !empty($options['count']) ? true : false); + $data->eagerlyResult($data, $options['with'], is_object($result) ? get_class($result) : ''); } // 关联统计 if (!empty($options['with_count'])) { diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index a83ac53b..cf831f1b 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -13,7 +13,6 @@ namespace think\model\relation; use think\Db; use think\db\Query; -use think\Loader; use think\Model; use think\model\Pivot; use think\model\Relation; @@ -81,10 +80,9 @@ class BelongsToMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -112,10 +110,7 @@ class BelongsToMany extends Relation if (!isset($data[$result->$pk])) { $data[$result->$pk] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); - } + $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } @@ -129,10 +124,9 @@ class BelongsToMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -147,10 +141,6 @@ class BelongsToMany extends Relation if (!isset($data[$pk])) { $data[$pk] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$pk])); - } $result->setAttr($relation, $this->resultSetBuild($data[$pk], $class)); } } diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index ed5fb0be..08e1e81e 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -13,7 +13,6 @@ namespace think\model\relation; use think\Db; use think\db\Query; -use think\Loader; use think\Model; use think\model\Relation; @@ -55,10 +54,9 @@ class HasMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -85,10 +83,6 @@ class HasMany extends Relation if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$localKey])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); } } @@ -102,10 +96,9 @@ class HasMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { $localKey = $this->localKey; $foreignKey = $this->foreignKey; @@ -116,10 +109,6 @@ class HasMany extends Relation if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$localKey])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$localKey], $class)); } } diff --git a/library/think/model/relation/MorphMany.php b/library/think/model/relation/MorphMany.php index 9340bc42..b2e21013 100644 --- a/library/think/model/relation/MorphMany.php +++ b/library/think/model/relation/MorphMany.php @@ -13,7 +13,6 @@ namespace think\model\relation; use think\Db; use think\db\Query; -use think\Loader; use think\Model; use think\model\Relation; @@ -61,10 +60,9 @@ class MorphMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure, $class) { $morphType = $this->morphType; $morphKey = $this->morphKey; @@ -91,10 +89,6 @@ class MorphMany extends Relation if (!isset($data[$result->$pk])) { $data[$result->$pk] = []; } - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } } @@ -108,10 +102,9 @@ class MorphMany extends Relation * @param string $subRelation 子关联名 * @param \Closure $closure 闭包 * @param string $class 数据集对象名 为空表示数组 - * @param bool $count 是否统计 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class, $count) + public function eagerlyResult(&$result, $relation, $subRelation, $closure, $class) { $morphType = $this->morphType; $morphKey = $this->morphKey; @@ -119,10 +112,6 @@ class MorphMany extends Relation $pk = $result->getPk(); if (isset($result->$pk)) { $data = $this->eagerlyMorphToMany([$morphKey => $result->$pk, $morphType => $type], $relation, $subRelation, $closure); - if ($count) { - // 关联统计 - $result->setAttr(Loader::parseName($relation) . '_count', count($data[$result->$pk])); - } $result->setAttr($relation, $this->resultSetBuild($data[$result->$pk], $class)); } }