N+1 Query for Text Column in Tables
I have this model, Domain.
Domain has many Config Mappings.
Config Mappings belongs to Config Directory.
What I want to achieve is to:
1. Show the config id and and the directory as badge.
2. When a badge is clicked, open a new tab for the clicked badge.
This is what I have so far, but this is doing N+1 Query.
2 Replies
Did you try to load relations with: with(['configMappings.configDirectory']) in your table query ?
Here's your n+1:
$configDirectory = ConfigDirectory::find($state);
Use this instead of loading it manually again:
->formatStateUsing(function (ConfigDirectory $configDirectory) {
Ah, that might return the table record though. What's $state
if you just use TextColumn::make('configMappings.configDirectory')
(no .id
) ?