inner join with containable cakephp
08:22 24 Aug 2013

I have 3 tables, restaurants, orders, users. orders table has fields restaurant_id, status and user_id.

restaurant -> hasMany orders
orders belogsTo Restaurant
orders belongsTo users

I need to find only those restaurants that have order with status = 1, and at the same time need to fetch user's info.

So, I am making inner join with orders table,

$options['joins'] = array(
    array('table' => 'orders',
        'alias' => 'Order',
        'type' => 'INNER',
        'conditions' => array(
            'Restaurant.id = Order.restaurant_id',
        )
    )
);

But how Can I also get users' information along with this, because according to cake documentation http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables, allowed params here are table, alias, type, conditions. Is there a some way that I can embed the sql query of getting user's info in the final query? Yes, the alternative will be to write the custom query, but is not there a way to do with cake.

Thanks

update

The best solution in this case was to write custom sql query.

cakephp join cakephp-2.3