mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-09-03 13:51:38 +08:00
改进多对多关联
This commit is contained in:
@@ -152,12 +152,16 @@ class HasMany extends Relation
|
||||
* 创建关联统计子查询
|
||||
* @access public
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $name 统计数据别名
|
||||
* @return string
|
||||
*/
|
||||
public function getRelationCountQuery($closure)
|
||||
public function getRelationCountQuery($closure, &$name = null)
|
||||
{
|
||||
if ($closure) {
|
||||
call_user_func_array($closure, [ & $this->query]);
|
||||
$return = call_user_func_array($closure, [ & $this->query]);
|
||||
if ($return && is_string($return)) {
|
||||
$name = $return;
|
||||
}
|
||||
}
|
||||
$localKey = $this->localKey ?: $this->parent->getPk();
|
||||
return $this->query->whereExp($this->foreignKey, '=' . $this->parent->getTable() . '.' . $localKey)->fetchSql()->count();
|
||||
|
||||
Reference in New Issue
Block a user