From ac97882da912cace9918a3ad5b1f913ae26c19df Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 6 May 2016 23:31:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Relation=E7=9A=84save?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/model/Relation.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index c9948ea4..5065500b 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -158,8 +158,8 @@ class Relation $data = $this->eagerlyOneToMany($model, [ $foreignKey => [ 'in', - $range - ] + $range, + ], ], $relation, $subRelation, $closure); // 关联数据封装 @@ -186,8 +186,8 @@ class Relation $data = $this->eagerlyManyToMany($model, [ 'pivot.' . $foreignKey => [ 'in', - $range - ] + $range, + ], ], $relation, $subRelation); // 关联数据封装 @@ -465,14 +465,14 @@ class Relation */ public function save($data, array $pivot = []) { - if ($data instanceof Model) { - $data = $data->toArray(); - } // 判断关联类型 switch ($this->type) { case self::HAS_ONE: case self::BELONGS_TO: case self::HAS_MANY: + if ($data instanceof Model) { + $data = $data->toArray(); + } // 保存关联表数据 $data[$this->foreignKey] = $this->parent->{$this->localKey}; $model = new $this->model;