Skip to content

Commit c42def9

Browse files
committed
fix: use morphTo with withTrashed
1 parent e26c877 commit c42def9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Relations/MorphTo.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ protected function getResultsByType($type)
2929

3030
$key = $instance->getKeyName();
3131

32-
$query = $instance->newQuery();
32+
// Copied this block from the parent method, based on the bug report at
33+
// https://github.com/mongodb/laravel-mongodb/issues/1361
34+
$query = $this->replayMacros($instance->newQuery())
35+
->mergeConstraintsFrom($this->getQuery())
36+
->with(array_merge(
37+
$this->getQuery()->getEagerLoads(),
38+
(array) ($this->morphableEagerLoads[get_class($instance)] ?? [])
39+
))
40+
->withCount(
41+
(array) ($this->morphableEagerLoadCounts[get_class($instance)] ?? [])
42+
);
3343

3444
return $query->whereIn($key, $this->gatherKeysByType($type, $instance->getKeyType()))->get();
3545
}

0 commit comments

Comments
 (0)