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'),
No description
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
1 Reply
Solution
Subhendu
Subhendu7mo ago
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),
Want results from more Discord servers?
Add your server