From 6e5d6fa7b28ebb67434d0844325797b6eb020e0f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 3 Apr 2017 09:37:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsTo.php | 5 ++++- library/think/model/relation/HasOne.php | 5 ++++- library/think/model/relation/MorphOne.php | 5 ++++- library/think/model/relation/MorphTo.php | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index 9e443d54..630719c0 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -54,7 +54,10 @@ class BelongsTo extends OneToOne ->where($this->localKey, $this->parent->$foreignKey) ->relation($subRelation) ->find(); - $relationModel->setParent(clone $this->parent); + + if ($relationModel) { + $relationModel->setParent(clone $this->parent); + } return $relationModel; } diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index 991a594f..e5a557a0 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -51,7 +51,10 @@ class HasOne extends OneToOne } // 判断关联类型执行查询 $relationModel = $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find(); - $relationModel->setParent(clone $this->parent); + + if ($relationModel) { + $relationModel->setParent(clone $this->parent); + } return $relationModel; } diff --git a/library/think/model/relation/MorphOne.php b/library/think/model/relation/MorphOne.php index b58b0419..e22198bb 100644 --- a/library/think/model/relation/MorphOne.php +++ b/library/think/model/relation/MorphOne.php @@ -56,7 +56,10 @@ class MorphOne extends Relation call_user_func_array($closure, [ & $this->query]); } $relationModel = $this->relation($subRelation)->find(); - $relationModel->setParent(clone $this->parent); + + if ($relationModel) { + $relationModel->setParent(clone $this->parent); + } return $relationModel; } diff --git a/library/think/model/relation/MorphTo.php b/library/think/model/relation/MorphTo.php index 70f1dc03..d67989c4 100644 --- a/library/think/model/relation/MorphTo.php +++ b/library/think/model/relation/MorphTo.php @@ -58,7 +58,10 @@ class MorphTo extends Relation // 主键数据 $pk = $this->parent->$morphKey; $relationModel = (new $model)->relation($subRelation)->find($pk); - $relationModel->setParent(clone $this->parent); + + if ($relationModel) { + $relationModel->setParent(clone $this->parent); + } return $relationModel; } From 2b4ddaa35c5a5cc97e579758d9ec06240e7e22c2 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 3 Apr 2017 22:34:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/Model.php b/library/think/Model.php index 9024c30c..2e5531e5 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -1258,7 +1258,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess /** * 返回模型的错误信息 * @access public - * @return string + * @return string|array */ public function getError() {