改进关联统计

This commit is contained in:
thinkphp
2016-12-26 15:52:53 +08:00
parent bfcc08cdeb
commit a74b842d71
4 changed files with 61 additions and 2 deletions

View File

@@ -161,6 +161,17 @@ class BelongsToMany extends Relation
return $count;
}
/**
* 获取关联统计子查询
* @access public
* @param \Closure $closure 闭包
* @return string
*/
public function getRelationCountQuery($closure)
{
return $this->belongsToManyQuery($this->middle, $this->foreignKey, $this->localKey, ['pivot.' . $this->localKey => ['exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk()]])->fetchSql()->count();
}
/**
* 多对多 关联模型预查询
* @access public