How to avoid extra queries created when related data is displayed?
The following adds a tooltip to show:
"booking xyz has 1 deal"
Or,
"booking xyz has 2 deals"
(implementing Str::plural) with the number of records in the related "deals" table.
The above adds two extra queries, how can I still show the icon with the records count but avoid extra queries?
Any advice is much appreciated.
Thank you.
2 Replies
Would it not help eager load deals in
getTableQuery
method and instead of counting on new query, count collection so $record->deals->count()
@bytexr of course it helps... thank you! Much appreciated...