I just started playing with Laravel 4 and Eloquent. I have a blog table and lots of other related tables to it:
blog <- main info about the blog record
blog_lang <- translations for each blog record
blog_categories <- name speaks for itself
blog_categories_lang <- translations for blog categories titles
blog_to_categories <- pivot table between blog and blog_categories
blog hasMany blog_lang.
blog_categories hasMany blog_categories_lang
blog belongsToMany blog_categories
I want to show the following info in one grid : blog_id
, blog_title
, username
, and all categories:
$data['blogs'] = Blog::with(array(
'translations' => function ($q) {
$q->where('lang_id', '=', 1);
},
'user',
'categories',
'categories.translations' => function ($q) {
$q->where('lang_id', '=', 1);
}
))->get();
This executes 5 queries... aren't they a little too many? Will it be better to just use Fluent
and join all these tables with 1 bigger query?