mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
支持关联查询嵌套预载入
This commit is contained in:
@@ -749,6 +749,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
foreach ($relations as $relation) {
|
foreach ($relations as $relation) {
|
||||||
$range = [];
|
$range = [];
|
||||||
$data = [];
|
$data = [];
|
||||||
|
if (strpos($relation, '.')) {
|
||||||
|
list($relation, $subRelation) = explode('.', $relation);
|
||||||
|
}
|
||||||
$model = $this->$relation();
|
$model = $this->$relation();
|
||||||
list($type, $foreignKey, $localKey) = $this->relation;
|
list($type, $foreignKey, $localKey) = $this->relation;
|
||||||
foreach ($resultSet as $result) {
|
foreach ($resultSet as $result) {
|
||||||
@@ -756,7 +759,12 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$range[] = $result->$localKey;
|
$range[] = $result->$localKey;
|
||||||
}
|
}
|
||||||
// 预载入关联查询
|
// 预载入关联查询
|
||||||
|
if (isset($subRelation)) {
|
||||||
|
// 嵌套预载入
|
||||||
|
$list = $model::where($foreignKey, 'in', $range)->with($subRelation)->select();
|
||||||
|
} else {
|
||||||
$list = $model::where($foreignKey, 'in', $range)->select();
|
$list = $model::where($foreignKey, 'in', $range)->select();
|
||||||
|
}
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case self::HAS_ONE:
|
case self::HAS_ONE:
|
||||||
case self::BELONGS_TO:
|
case self::BELONGS_TO:
|
||||||
|
|||||||
Reference in New Issue
Block a user