F
Filament6d ago
Vp

nested repeater n+1 query

I have model like "booking", "booking_item", and "booking_item_detail", so I try to create a repeater data while creating new booking
Repeater::make('items')
->relationship()
->schema([
Repeater::make('details')->relationship(),
]),
Repeater::make('items')
->relationship()
->schema([
Repeater::make('details')->relationship(),
]),
Relationships are HasMany
// Booking.php
public function items(): HasMany
{
return $this->hasMany(BookingItem::class);
}

// BookingItem.php
public function details(): HasMany
{
return $this->hasMany(BookingItemDetail::class);
}
// Booking.php
public function items(): HasMany
{
return $this->hasMany(BookingItem::class);
}

// BookingItem.php
public function details(): HasMany
{
return $this->hasMany(BookingItemDetail::class);
}
How can I prevent n+1 query
No description
Solution:
Created issue for the main questions, and others duplicate (that I found) can be resolved when using relationships, not options
GitHub
Duplicate query when using nested repeater (Repeater inside repeate...
Package filament/filament Package Version v4.3 Laravel Version v12.41.1 Livewire Version v3.7.1 PHP Version PHP 8.4.15 Problem description When declaring repeater inside repeater, it duplicate quer...
Jump to solution
5 Replies
98.dev
98.dev5d ago
I believe you need to eager-load it in your resource, like so:
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->with(['items.details']);
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()->with(['items.details']);
}
Vp
VpOP5d ago
I enabled Model::automaticallyEagerLoadRelationships(); and I also did like this, but it's same
98.dev
98.dev4d ago
Hmm.. not sure on this sorry! Hopefully somebody else can provide a clearer answer on this. Try creating a basic reproductive example, makes it easier to investigate.
Vp
VpOP3d ago
I think duplicate query, not exactly this example is caused by when using wizard and share fields with relations or select options For eg: I display State dropdown for edit only (I don't call it from create) but it still query when I am in create page Will try to check more and submit an issue with reproduction repo
Solution
Vp
Vp3h ago
Created issue for the main questions, and others duplicate (that I found) can be resolved when using relationships, not options
GitHub
Duplicate query when using nested repeater (Repeater inside repeate...
Package filament/filament Package Version v4.3 Laravel Version v12.41.1 Livewire Version v3.7.1 PHP Version PHP 8.4.15 Problem description When declaring repeater inside repeater, it duplicate quer...

Did you find this page helpful?