这听起来可能是一个显而易见的问题,但我只是想得到一些保证.
Using Laravel's eager loading functionality, from what I understand it will create two queries to return a whole list of related results (say if you're working with two tables). However, and correct me if I'm wrong, using a join statement will leave you with only one query, which creates one less round trip to the server's database (MySQL) and is a more efficient query.
I know that you can write join queries in Laravel, which is great, so the question is: am I incorrect to assume that when retrieving related data from two or more tables, should I not bother with eager loading and instead just write my own join statements?
****** Edit *******
一年后再回到这一点,我个人认为,只要把问题写出来,原封不动,把它们写好.
*编辑2*
好了,六年后,我一直在为此得分.
Whether I was unclear from the beginning or not, contrary to what I've said above, Eloquent at this point writes great queries. Use Eloquent - even if there's a slight query inefficiency, it allows you to write very clear, maintainable code which at this point in my career I would argue is more important in most cases. Only write raw queries and optimize in cases where performance enhancements are critical and you can measure the impact.