From 9ca4911c44be743459d788ad00a16c9c77d1bdc4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 27 Jun 2016 23:29:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=85=B3=E8=81=94=E9=A2=84?= =?UTF-8?q?=E8=BD=BD=E5=85=A5=E6=9F=A5=E8=AF=A2=20=E4=B8=A4=E4=B8=AA?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E6=A8=A1=E5=9E=8B=E6=9F=A5=E8=AF=A2=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 2 +- library/think/model/Relation.php | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index df66fa07..0f92143a 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -1466,7 +1466,7 @@ class Query unset($this->options['with_field']); } } - $this->field($field, false, $joinTable, $joinAlias, $joinName . '__'); + $this->field($field, false, $joinTable, $joinAlias, $relation . '__'); $i++; } elseif ($closure) { $with[$key] = $closure; diff --git a/library/think/model/Relation.php b/library/think/model/Relation.php index 070f6ea1..a065524c 100644 --- a/library/think/model/Relation.php +++ b/library/think/model/Relation.php @@ -302,23 +302,22 @@ class Relation */ protected function match($model, $relation, &$result) { - $modelName = Loader::parseName(basename(str_replace('\\', '/', $model))); // 重新组装模型数据 foreach ($result->toArray() as $key => $val) { if (strpos($key, '__')) { list($name, $attr) = explode('__', $key, 2); - if ($name == $modelName) { + if ($name == $relation) { $list[$name][$attr] = $val; unset($result->$key); } } } - if (!isset($list[$modelName])) { + if (!isset($list[$relation])) { // 设置关联模型属性 - $list[$modelName] = []; + $list[$relation] = []; } - $result->setAttr($relation, new $model($list[$modelName])); + $result->setAttr($relation, new $model($list[$relation])); } /**