Alert advice text
janpio opened this issue · 2 comments
Just started using this package ❤️
The alert says:
Found the following N+1 queries in this request:
Model: App\Balance => Relation: statement - You should add "with('statement')" to eager-load this relation.
Although it is great that the package tries to give advice (You should add "with('statement')" to eager-load this relation.), this might be "misleading":
What is actually happening in my code is a loop over $account->balances->groupBy('statement_id') (as $balances) where $balances[0]->statement is called. In this case the correct solution was adding $account->load('balances.statement');
Maybe there is a way to formulate the alert in a more code independent way that keeps it useful?
Yeah good idea. I wanted it to be easy to implement in your code, but something like this is hard to capture
Does the alert actually list multiple problems if it finds them?
Then one could just move the advice into a "footer" of the alert text that explains it more general:
You should add "with('relationname')" or "load('relationname')" to eager-load this relation in your Eloquent calls. Be aware the relationship affected might be a nested one.