From 4b9db8a6644fbf77adc1a125c0cc42ac7c32b0c0 Mon Sep 17 00:00:00 2001 From: yinggaozhen Date: Wed, 2 Aug 2017 20:17:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9ERelation=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=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 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 7777e231..bc16a576 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -11,6 +11,7 @@ namespace think; +use BadMethodCallException; use InvalidArgumentException; use think\db\Query; use think\exception\ValidateException; @@ -567,6 +568,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess * @access public * @param Relation $modelRelation 模型关联对象 * @return mixed + * @throws BadMethodCallException */ protected function getRelationData(Relation $modelRelation) { @@ -574,7 +576,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess $value = $this->parent; } else { // 首先获取关联数据 - $value = $modelRelation->getRelation(); + if (method_exists($modelRelation, 'getRelation')) { + $value = $modelRelation->getRelation(); + } else { + throw new BadMethodCallException('method not exists:' . get_class($modelRelation) . '-> getRelation'); + } } return $value; }