这是我的查询:
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
我保持这样做很好,但是希望能够将其定义为relations
稍后使用此类代码会更加舒适 这可行吗?我找不到任何例子。
答案 0 :(得分:1)
Additional options可以在关系声明中指定。
public function relations()
{
return array(
'orderShippingDate' => array(
// define you relation
'join' => '(/* subquery here*/) osdi ON osdi.id=orderShippingDate.id',
'joinType' => 'INNER JOIN'
),
);
}