改进关联统计

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

@@ -133,6 +133,21 @@ class MorphMany extends Relation
return $count;
}
/**
* 获取关联统计子查询
* @access public
* @param \Closure $closure 闭包
* @return string
*/
public function getRelationCountQuery($closure)
{
if ($closure) {
call_user_func_array($closure, [ & $this->query]);
}
return $this->query->where([$this->morphKey => ['exp', '=' . $this->parent->getTable() . '.' . $this->parent->getPk()], $this->morphType => $this->type])->fetchSql()->count();
}
/**
* 多态一对多 关联模型预查询
* @access public