改进HasMany关联的getRelationCountQuery方法

This commit is contained in:
thinkphp
2017-08-30 10:49:35 +08:00
parent a217d88e38
commit 8aacceac69

View File

@@ -159,11 +159,11 @@ class HasMany extends Relation
if ($closure) { if ($closure) {
call_user_func_array($closure, [ & $this->query]); call_user_func_array($closure, [ & $this->query]);
} }
$localKey = $this->localKey ?: $this->parent->getPk();
return $this->query->where([ return $this->query->where([
$this->foreignKey => [ $this->foreignKey => [
'exp', 'exp',
'=' . $this->parent->getTable() . '.' . $this->parent->getPk(), '=' . $this->parent->getTable() . '.' . $localKey,
], ],
])->fetchSql()->count(); ])->fetchSql()->count();
} }