修正关联withCount查询

This commit is contained in:
thinkphp
2018-04-16 12:46:58 +08:00
parent 3bf48cbfef
commit 513701788e
3 changed files with 6 additions and 9 deletions

View File

@@ -143,7 +143,7 @@ class HasMany extends Relation
if ($closure) {
call_user_func_array($closure, [ & $this->query]);
}
$count = $this->query->where([$this->foreignKey => $result->$localKey])->count();
$count = $this->query->where($this->foreignKey, $result->$localKey)->count();
}
return $count;
}
@@ -160,12 +160,7 @@ class HasMany extends Relation
call_user_func_array($closure, [ & $this->query]);
}
$localKey = $this->localKey ?: $this->parent->getPk();
return $this->query->where([
$this->foreignKey => [
'exp',
'=' . $this->parent->getTable() . '.' . $localKey,
],
])->fetchSql()->count();
return $this->query->whereExp($this->foreignKey, '=' . $this->parent->getTable() . '.' . $localKey)->fetchSql()->count();
}
/**