Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正多态一对多关联,类型未定义时,预载入查询数据集时抛出异常改为null,与查询模型对象和延迟获取保持一致 #460

Open
wants to merge 1 commit into
base: 3.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/model/relation/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,20 @@ public function eagerlyResultSet(array &$resultSet, string $relation, array $sub
foreach ($range as $key => $val) {
// 多态类型映射
$model = $this->parseModel($key);
$obj = new $model();
if (!is_null($closure)) {
$obj = $closure($obj);
}
$pk = $obj->getPk();
$list = $obj->with($subRelation)
->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
->select($val);
$data = [];
if (class_exists($model)) {
$obj = new $model();
if (!is_null($closure)) {
$obj = $closure($obj);
}
$pk = $obj->getPk();
$list = $obj->with($subRelation)
->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
->select($val);

foreach ($list as $k => $vo) {
$data[$vo->$pk] = $vo;
foreach ($list as $k => $vo) {
$data[$vo->$pk] = $vo;
}
}

foreach ($resultSet as $result) {
Expand Down