© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
2 replies
Subhendu

How to Eager Load Nested Relationship in table builder

I have accounts table with schema
id, name, parent_id
(Data in table)
1,"Base account",2
2,"Parent Account",3
3,"Super Parent Account",0
id, name, parent_id
(Data in table)
1,"Base account",2
2,"Parent Account",3
3,"Super Parent Account",0

App/Models/Account
 public function parent()
  {
      return $this->belongsTo(Account::class, 'parent_id');
  }
 public function parent()
  {
      return $this->belongsTo(Account::class, 'parent_id');
  }


When tried to display super parent account using table builder I am getting N+1 Query
here is my column
 TextColumn::make('parent.parent.account_name')
                ->label('Super Parent'),
 TextColumn::make('parent.parent.account_name')
                ->label('Super Parent'),
image.png
Solution
It was due to N+1 detector package. In this case you need to put threshold value in config/querydectector.php to
'threshold' => (int) env('QUERY_DETECTOR_THRESHOLD', 2),
'threshold' => (int) env('QUERY_DETECTOR_THRESHOLD', 2),
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

how to eager load in relationship manager
FilamentFFilament / ❓┊help
3y ago
Table apply filter in a eager load relationship
FilamentFFilament / ❓┊help
2y ago
How to eager load relationship inside infolist repeatable entry
FilamentFFilament / ❓┊help
2y ago
Advanced Nested Relationship Form builder
FilamentFFilament / ❓┊help
16mo ago