I want to make a model relation in the relations method
For example in the customer model
public function relations() {
return array(
....
'recentOrder' => array(self::HAS_ONE, 'orders', 'customer_id', 'condition' => 'date_order=(SELECT MAX(date_order) FROM orders WHERE orders.customer_id=?how can I use t.id ?)'),
....
);
}
But I can’t find out how pass the customer id parameter in the condition.
I know that I could make a function to get the desired result but I am curious if it could be done in relations directly
Using ‘order’ (especially without index on the specific column) has performance issues, even using limit 1 (HAS_ONE). So your code works but I would like something different
'recentOrder' => array(self::HAS_ONE, 'orders', 'customer_id',
'condition' => 'date_order=
(SELECT MAX(date_order) FROM orders WHERE orders.customer_id = recentOrder.customer_id)'),
//where recentOrder.customer_id is a trick to filter only the specific customer model id