From 81a74f90ea93bb15467ad7faf3ff20b50ed5c84f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 12 Apr 2016 22:20:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bwith=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 0ba0f4d4..3565e3f8 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -758,14 +758,15 @@ abstract class Model implements \JsonSerializable, \ArrayAccess // 支持闭包查询过滤关联条件 call_user_func_array($relation, [ & $db]); $relation = $key; - } elseif (is_string($relation) && strpos($relation, '.')) { - list($relation, $subRelation) = explode('.', $relation); } } $class = new static(); foreach ($with as $key => $name) { + if (is_string($name) && strpos($name, '.')) { + list($name) = explode('.', $name); + } $i = 0; $model = $class->$name(); list($type, $foreignKey, $localKey) = $class->relation; @@ -877,8 +878,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess case self::HAS_MANY: case self::BELONGS_TO_MANY: if (isset($result->$localKey)) { - $data = $this->modelRelationQuery($model, $resultSet, [$foreignKey => $result->$localKey], $relation, $subRelation); - + $data = $this->modelRelationQuery($model, [$foreignKey => $result->$localKey], $relation, $subRelation); // 关联数据封装 if (!isset($data[$result->$localKey])) { $data[$result->$localKey] = [];