Tebe
Tebe

Reputation: 3214

Yii relations subquery

This is the query I have:

select * from order_shipping_date osd inner join  
(SELECT MAX(osd.id) as id FROM  order_shipping_date osd 
group by osd.order_id) osdi ON osd.id = osdi.id 

I'm fine with keeping it so, but would like to make it possible to define it as relations

This is more comfy to use such code later Is this doable at all? I can't find any examples.

Upvotes: 0

Views: 260

Answers (1)

SiZE
SiZE

Reputation: 2267

Additional options can be specified in relationship declaration.

public function relations()
{
    return array(
        'orderShippingDate' => array(
            // define you relation
            'join' => '(/* subquery here*/) osdi ON osdi.id=orderShippingDate.id',
            'joinType' => 'INNER JOIN'
        ),
    );
}

Upvotes: 1

Related Questions