Soft-deleted relations
Found other posts before but no answers.
Works when campaign is soft-deleted:
TextColumn::make('campaign.user.name')
However, this doesn't work:
->url(fn ($record) => UserResource::getUrl('edit', [$record->campaign->user]))
modifyQueryUsing is eager loading it - however that doesn't seem to affect $record.
Query being run:
select * from
campaigns
where campaigns
.id
in (5) and campaigns
.deleted_at
is null
Modify query on the table:
->modifyQueryUsing(function ($query) {
return $query->with(['campaign' => function ($query) {
$query->withTrashed()->with(['user']);
}]);
})4 Replies
Appears nested relations are not passed through modifyQueryUsing?
Appears to be a bug, no?
TextColumn::make('campaign.user.email')
->modifyQueryUsing(function ($query) {
return $query->with([
'campaign' => function ($query) {
$query->withTrashed()->with('user');
},
]);
})
Solution:
->modifyQueryUsing(function ($query) {
return $query->with([
'campaign' => fn ($query) => $query->withTrashed(),
'campaign.user' => fn ($query) => $query->withTrashed(),
]);
})
So the issue was it was getting the user because it was the wrong query?
Well, it behaves strange.
campaign.user.email
campaign = soft deleted
user = not soft deleted
Only works when both of these relations are withTrashed.
'campaign' => fn ($query) => $query->withTrashed(),
'campaign.user' => fn ($query) => $query->withTrashed(),
Maybe that's expected behaviour? I'd imagine the second one alone should be enough
Hm. Interesting. Thanks for clarifying