From 6aefdd0511b08c6f656a7e92bfbc463ccc6f15fe Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 21 Apr 2016 10:57:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E5=AF=B9=E5=A4=9A=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=94=AF=E6=8C=81=E6=9D=A1=E4=BB=B6=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 876d7ce5..3cc2cf86 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -558,7 +558,12 @@ class Relation { if ($this->model) { $model = new $this->model; - return call_user_func_array([$model->db(), $method], $args); + $db = $model->db(); + if (self::HAS_MANY == $this->type && isset($this->parent->{$this->localKey})) { + // 关联查询带入关联条件 + $db->where($this->foreignKey, $this->parent->{$this->localKey}); + } + return call_user_func_array([$db, $method], $args); } else { throw new Exception(__CLASS__ . ':' . $method . ' method not exist'); }