I have the following tables:
- restaurants (restaurant.id, restaurant.name)
- menus (menu.id, menu.name, menu.active, menu.restaurant_id)
I want to have a list with all restaurants with the active menus (menu.active = true):
- restaurant2
- menu1
- menu4
- restaurant5
-menu3
- restaurant19
- menu34
- menu33
My first idea was something like this:
$options['contain'] = array(
'Menu' => array(
'conditions' => $menuParams //array('Menu.active' => '1') //$menuParams
)
);
This doen't work becaus all restaurants will be listed. I want to have only restaurants with active menus.
Next idea: using join
$options['joins'] = array(
array('table' => 'menus',
'alias' => 'Menu',
'type' => 'RIGHT',
'conditions' => array(
'Menu.restaurant_id = Restaurant.id',
)
)
);
Not good, because, I don't have the ordered list I want. I need the menus grouped by the restaurant. Look above.
Is it the right way to make a join with restaurants and menus(active = true) and then using the contain to get the ordered list? I think that could work but I think also there is an easier way, right?
Any help is welcome! Thank you.