From 85b71a30880b7d96f3b22dcc74fa802a489c74c7 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Apr 2017 12:39:38 +0800 Subject: [PATCH] =?UTF-8?q?Model=E7=B1=BB=E6=B7=BB=E5=8A=A0getRelation?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E=E8=8E=B7=E5=8F=96=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/think/Model.php b/library/think/Model.php index 3b24b135..8553fec6 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -354,6 +354,23 @@ abstract class Model implements \JsonSerializable, \ArrayAccess return $this; } + /** + * 获取当前模型的关联模型数据 + * @access public + * @param string $name 关联方法名 + * @return mixed + */ + public function getRelation($name = null) + { + if (is_null($name)) { + return $this->relation; + } elseif (array_key_exists($name, $this->relation)) { + return $this->relation[$name]; + } else { + return; + } + } + /** * 设置关联数据对象值 * @access public