From 77d2731892604af646e4186f95b93c68decc0afc Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 11:28:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=85=B3=E8=81=94=E5=A4=9A?= =?UTF-8?q?=E5=AF=B9=E5=A4=9A=E4=B8=80=E5=A4=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 7be2ac46..5bfd0773 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -71,6 +71,15 @@ class Relation return $this->parent; } + /** + * 获取关联的查询对象 + * @access public + */ + public function getQuery() + { + return $this->query; + } + /** * 获取当前关联信息 * @access public @@ -118,7 +127,7 @@ class Relation // 关联查询 $pk = $this->parent->getPk(); $condition['pivot.' . $localKey] = $this->parent->$pk; - $result = $this->belongsToManyQuery($relation->getModel(), $this->middle, $foreignKey, $localKey, $condition)->select(); + $result = $this->belongsToManyQuery($relation->getQuery(), $this->middle, $foreignKey, $localKey, $condition)->select(); foreach ($result as $set) { $pivot = []; foreach ($set->getData() as $key => $val) { @@ -604,7 +613,7 @@ class Relation // 关联查询封装 $tableName = $model->getTable(); $relationFk = $model->getPk(); - return $model::field($tableName . '.*') + return $model->field($tableName . '.*') ->field(true, false, $table, 'pivot', 'pivot__') ->join($table . ' pivot', 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) ->where($condition);