From 80e1b5261569ba0161e90fa47a512feda99629b9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Thu, 27 Apr 2017 11:25:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BModel=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=B1=9E=E6=80=A7=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 1310cf0f..8cd3259d 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -56,6 +56,8 @@ abstract class Model implements \JsonSerializable, \ArrayAccess protected $pk; // 数据表字段信息 留空则自动获取 protected $field = []; + // 关联属性 + protected $relationAttr = []; // 只读字段 protected $readonly = []; // 显示属性 @@ -1083,11 +1085,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess { $relation = Loader::parseName($attr, 1, false); - if (method_exists($this, $relation)) { + if (!empty($this->relationAttr) && in_array($attr, $this->relationAttr)) { + return $relation; + } elseif (method_exists($this, $relation)) { return $relation; } return false; - } /**