修正多对多预载入查询

This commit is contained in:
thinkphp
2016-07-02 18:51:28 +08:00
parent 2cb8022982
commit 0f58b08bec

View File

@@ -197,7 +197,7 @@ class Relation
if (!empty($range)) { if (!empty($range)) {
// 查询关联数据 // 查询关联数据
$data = $this->eagerlyManyToMany($model, [ $data = $this->eagerlyManyToMany($model, [
'pivot.' . $foreignKey => [ 'pivot.' . $localKey => [
'in', 'in',
$range, $range,
], ],
@@ -277,7 +277,7 @@ class Relation
if (isset($result->$pk)) { if (isset($result->$pk)) {
$pk = $result->$pk; $pk = $result->$pk;
// 查询管理数据 // 查询管理数据
$data = $this->eagerlyManyToMany($model, ['pivot.' . $foreignKey => $pk], $relation, $subRelation); $data = $this->eagerlyManyToMany($model, ['pivot.' . $localKey => $pk], $relation, $subRelation);
// 关联数据封装 // 关联数据封装
if (!isset($data[$pk])) { if (!isset($data[$pk])) {
@@ -374,7 +374,7 @@ class Relation
} }
} }
$set->pivot = new Pivot($pivot, $this->middle); $set->pivot = new Pivot($pivot, $this->middle);
$data[$set->$foreignKey][] = $set; $data[$pivot[$localKey]][] = $set;
} }
return $data; return $data;
} }