mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改进关联预载入查询 两个相同模型查询的问题
This commit is contained in:
@@ -1466,7 +1466,7 @@ class Query
|
|||||||
unset($this->options['with_field']);
|
unset($this->options['with_field']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->field($field, false, $joinTable, $joinAlias, $joinName . '__');
|
$this->field($field, false, $joinTable, $joinAlias, $relation . '__');
|
||||||
$i++;
|
$i++;
|
||||||
} elseif ($closure) {
|
} elseif ($closure) {
|
||||||
$with[$key] = $closure;
|
$with[$key] = $closure;
|
||||||
|
|||||||
@@ -302,23 +302,22 @@ class Relation
|
|||||||
*/
|
*/
|
||||||
protected function match($model, $relation, &$result)
|
protected function match($model, $relation, &$result)
|
||||||
{
|
{
|
||||||
$modelName = Loader::parseName(basename(str_replace('\\', '/', $model)));
|
|
||||||
// 重新组装模型数据
|
// 重新组装模型数据
|
||||||
foreach ($result->toArray() as $key => $val) {
|
foreach ($result->toArray() as $key => $val) {
|
||||||
if (strpos($key, '__')) {
|
if (strpos($key, '__')) {
|
||||||
list($name, $attr) = explode('__', $key, 2);
|
list($name, $attr) = explode('__', $key, 2);
|
||||||
if ($name == $modelName) {
|
if ($name == $relation) {
|
||||||
$list[$name][$attr] = $val;
|
$list[$name][$attr] = $val;
|
||||||
unset($result->$key);
|
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]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user