Skip to content

Commit

Permalink
fix: 多态关联模型多态类型未定义时抛出异常
Browse files Browse the repository at this point in the history
  • Loading branch information
gitlilimin authored and liu21st committed Sep 27, 2022
1 parent d86a204 commit e1974a4
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/model/relation/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,18 @@ protected function eagerlyMorphToOne(string $model, string $relation, Model $res
{
// 预载入关联查询 支持嵌套预载入
$pk = $this->parent->{$this->morphKey};
$data = (new $model)->with($subRelation)
->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
->find($pk);

if ($data) {
$data->setParent(clone $result);
$data->exists(true);
$data = null;

if(\class_exists($model)){
$data = (new $model)->with($subRelation)
->cache($cache[0] ?? false, $cache[1] ?? null, $cache[2] ?? null)
->find($pk);

if ($data) {
$data->setParent(clone $result);
$data->exists(true);
}
}

$result->setRelation($relation, $data ?: null);
Expand Down

0 comments on commit e1974a4

Please sign in to comment.