F
Filamentβ€’8mo ago
Mnemonic

Repeaters and eager loading relationships

I'm chasing down an issue with some n+1 queries that I'm having trouble getting to eager load properly, and I think it's due to the repeater causing the relationship to be fetched for each item. I'm having trouble figured out how to combine these queries into one. I've tried adding eager loading where I can:
Repeater::make('departments')
->relationship('departments', modifyQueryUsing: function(Builder $query) {
return $query->with([
'shifts' => [
'call',
'user'
]
]);
Repeater::make('departments')
->relationship('departments', modifyQueryUsing: function(Builder $query) {
return $query->with([
'shifts' => [
'call',
'user'
]
]);
and
TableRepeater::make('shift')
->relationship('shifts', modifyQueryUsing: function (Builder $query) {
return $query->with(['user', 'call']);
})
TableRepeater::make('shift')
->relationship('shifts', modifyQueryUsing: function (Builder $query) {
return $query->with(['user', 'call']);
})
but I'm seeing a zillion repeated queries... I feel like I need to do this at some higher level, but I'm not seeing where that level might be.
No description
1 Reply
Mnemonic
MnemonicOPβ€’8mo ago
πŸ†™
Want results from more Discord servers?
Add your server