From 34579bfa4456495e648b938d083c743948a46588 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 22 Jun 2016 23:51:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84relati?= =?UTF-8?q?on=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index a9be8662..ddeeb95e 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -164,10 +164,17 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * 获取关联模型实例 * @access protected - * @return Relation + * @param string|array $relation 关联查询 + * @return Relation|Query */ - protected function relation() + protected function relation($relation = null) { + if (!is_null($relation)) { + // 执行关联查询 + return $this->db->relation($relation); + } + + // 获取关联对象实例 if (is_null($this->relation)) { $this->relation = new Relation($this); }