From 8aacceac69276405cc2c9a3dbceba1d9e4bc101a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 30 Aug 2017 10:49:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BHasMany=E5=85=B3=E8=81=94?= =?UTF-8?q?=E7=9A=84getRelationCountQuery=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/HasMany.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/think/model/relation/HasMany.php b/library/think/model/relation/HasMany.php index ba307ec7..3d80c2c1 100644 --- a/library/think/model/relation/HasMany.php +++ b/library/think/model/relation/HasMany.php @@ -159,11 +159,11 @@ class HasMany extends Relation if ($closure) { call_user_func_array($closure, [ & $this->query]); } - + $localKey = $this->localKey ?: $this->parent->getPk(); return $this->query->where([ $this->foreignKey => [ 'exp', - '=' . $this->parent->getTable() . '.' . $this->parent->getPk(), + '=' . $this->parent->getTable() . '.' . $localKey, ], ])->fetchSql()->count(); }