php - Laravel Eloquent - Is it inefficient -
i'm looking @ developing new site laravel. reading tutorial on http://vegibit.com/laravel-eloquent-orm-tutorial/, regarding using eloquent join tables , retrieve data. in last example trying join still eloquent executing 2 queries instead of one. eloquent inefficient or poor example? seems have been done single left join query. can provide insight on this? there better way execute query? specific example is:
route::get('/', function() { $paintings = painting::with('painter')->get(); foreach($paintings $painting){ echo $painting->painter->username; echo ' painted '; echo $painting->title; echo '<br>'; } });
results in following queries:
string ‘select * paintings‘ (length=25) string ‘select * painters painters.id in (?, ?, ?)’ (length=59) leonardo da vinci painted mona lisa leonardo da vinci painted last supper vincent van gogh painted the starry night vincent van gogh painted the potato eaters rembrandt painted the night watch rembrandt painted the storm on sea of galilee
eloquent extremely useful building , has query caching it's easy use might not ideal big projects need scale on time, approach use repository pattern contracts way can still use power of eloquent , have system allow me change implementation if needed.
Comments
Post a Comment