From e2e217f1d693d39403bb68b96736e34957ff7677 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 22 Jan 2017 17:36:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E4=B8=80=E5=AF=B9=E4=B8=80?= =?UTF-8?q?=E5=85=B3=E8=81=94=E9=A2=84=E8=BD=BD=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/relation/BelongsTo.php | 9 ++++----- library/think/model/relation/HasOne.php | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/library/think/model/relation/BelongsTo.php b/library/think/model/relation/BelongsTo.php index 1a3cad6f..2f067c30 100644 --- a/library/think/model/relation/BelongsTo.php +++ b/library/think/model/relation/BelongsTo.php @@ -11,7 +11,6 @@ namespace think\model\relation; -use think\Exception; use think\Loader; use think\Model; @@ -86,12 +85,12 @@ class BelongsTo extends OneToOne foreach ($resultSet as $result) { // 关联模型 if (!isset($data[$result->$localKey])) { - throw new Exception('relation data not exists :' . $this->model); + $relationModel = null; } else { $relationModel = $data[$result->$localKey]; } - if (!empty($this->bindAttr)) { + if ($relationModel && !empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($relationModel, $result, $this->bindAttr); } @@ -117,11 +116,11 @@ class BelongsTo extends OneToOne $data = $this->eagerlyWhere($this, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure); // 关联模型 if (!isset($data[$result->$localKey])) { - throw new Exception('relation data not exists :' . $this->model); + $relationModel = null; } else { $relationModel = $data[$result->$localKey]; } - if (!empty($this->bindAttr)) { + if ($relationModel && !empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($relationModel, $result, $this->bindAttr); } diff --git a/library/think/model/relation/HasOne.php b/library/think/model/relation/HasOne.php index 751f53d5..9882667e 100644 --- a/library/think/model/relation/HasOne.php +++ b/library/think/model/relation/HasOne.php @@ -11,7 +11,6 @@ namespace think\model\relation; -use think\Exception; use think\Loader; use think\Model; @@ -113,11 +112,11 @@ class HasOne extends OneToOne foreach ($resultSet as $result) { // 关联模型 if (!isset($data[$result->$localKey])) { - throw new Exception('relation data not exists : ' . $this->model); + $relationModel = null; } else { $relationModel = $data[$result->$localKey]; } - if (!empty($this->bindAttr)) { + if ($relationModel && !empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($relationModel, $result, $this->bindAttr); } @@ -144,12 +143,12 @@ class HasOne extends OneToOne // 关联模型 if (!isset($data[$result->$localKey])) { - throw new Exception('relation data not exists :' . $this->model); + $relationModel = null; } else { $relationModel = $data[$result->$localKey]; } - if (!empty($this->bindAttr)) { + if ($relationModel && !empty($this->bindAttr)) { // 绑定关联属性 $this->bindAttr($relationModel, $result, $this->bindAttr); }