From 8c79c435f57cc9323dfcc129a0ffbdba19d2d9a7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 17 Mar 2017 19:42:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsToMany.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/model/relation/BelongsToMany.php b/library/think/model/relation/BelongsToMany.php index cd334892..026334ed 100644 --- a/library/think/model/relation/BelongsToMany.php +++ b/library/think/model/relation/BelongsToMany.php @@ -374,13 +374,13 @@ class BelongsToMany extends Relation protected function belongsToManyQuery($foreignKey, $localKey, $condition = []) { // 关联查询封装 - $tableName = $this->query->getTable(); - $relationFk = $this->query->getPk(); - $table = $this->pivot->getTable(); - $query = $this->query->field($tableName . '.*') + $tableName = $this->query->getTable(); + $table = $this->pivot->getTable(); + $query = $this->query->field($tableName . '.*') ->field(true, false, $table, 'pivot', 'pivot__'); if (empty($this->baseQuery)) { + $relationFk = $this->query->getPk(); $query->join($table . ' pivot', 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) ->where($condition); }