From a02c7321bb5aba21bc81f5cc566d897a3e2ddc0d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 1 Dec 2016 10:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94=E5=A4=9A?= =?UTF-8?q?=E5=AF=B9=E5=A4=9A=E7=9A=84=E6=9F=A5=E8=AF=A2=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0getModel=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.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index c206c91d..7be2ac46 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -21,11 +21,11 @@ class Relation { const HAS_ONE = 1; const HAS_MANY = 2; - const HAS_MANY_THROUGH = 5; const BELONGS_TO = 3; const BELONGS_TO_MANY = 4; - const MORPH_MANY = 7; + const HAS_MANY_THROUGH = 5; const MORPH_TO = 6; + const MORPH_MANY = 7; // 父模型对象 protected $parent; @@ -51,6 +51,7 @@ class Relation protected $where; // 关联查询参数 protected $option; + /** * 架构函数 * @access public @@ -61,6 +62,15 @@ class Relation $this->parent = $model; } + /** + * 获取关联的所属模型 + * @access public + */ + public function getModel() + { + return $this->parent; + } + /** * 获取当前关联信息 * @access public @@ -108,7 +118,7 @@ class Relation // 关联查询 $pk = $this->parent->getPk(); $condition['pivot.' . $localKey] = $this->parent->$pk; - $result = $this->belongsToManyQuery($relation, $this->middle, $foreignKey, $localKey, $condition)->select(); + $result = $this->belongsToManyQuery($relation->getModel(), $this->middle, $foreignKey, $localKey, $condition)->select(); foreach ($result as $set) { $pivot = []; foreach ($set->getData() as $key => $val) {