Answer the question
In order to leave comments, you need to log in
How to sort tables in Yii?
The "Users" table and the "Orders" table.
Users have many orders.
We display the last orders of the user in the table, so that sorting by them works.
Model "User" function relations
'lastorder'=>array(self::HAS_MANY,'Orders','userid','joinType'=>'INNER JOIN','limit'=>1, 'order'=>'date_time_reg desc'),<br>
$criteria->with = array('lastorder');// подключаем то что получили выше <br>
$criteria->compare('lastorder[0].name',$this->lastordername, false);<br>
Answer the question
In order to leave comments, you need to log in
You need to add a variable to the user:
public $lastorderName;
In rules add lastorderName to safe.
In search it would be:
$criteria->compare('lastorder.name', $this->lastorderName, false);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question