Answer the question
In order to leave comments, you need to log in
Is with evil in Laravel?
Is it evil to use with(<modelName>)
in Laravel to join tables and fetch?
For example, this call will create 3 separate SELECT queries for each connection (debugged):
ProductModel::with(['ProductPrice', 'ProductDiscount', 'ProductUser'])...
Answer the question
In order to leave comments, you need to log in
User::with('comments')->get()
This:
select * from `users`
select * from `comments` where `comments`.`user_id` in (1, 2, 3, 4, 5)
JOINs are not always faster. Although in the general case they are recommended instead of several queries or subqueries.
I think the reason is that tables for models can belong to different bases, and it will still work.
And now let's check how this join will work if we add LIMIT 1 to the end, for example;)
And, as it were, 3 requests are a penny.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question