Answer the question
In order to leave comments, you need to log in
How to make order by on related data in Yii1 in AR?
Good afternoon,
There are tables:
mc_rooms
-------------
id
name
and
ms_tarifs
-------------
id
room_id
price_small
For example, a room has several rates:
Room1: Tariff1 - 500r , Tariff2 - 600r, Tariff3 - 700r
Number2: Tariff4 - 200r , Tariff5 - 500r, Tariff6 - 800r
I would like to sort the rooms of a certain hostel by price_small of the cheapest rate.
This must be done through Cdbcritera, as I understand it. I do not fully understand how to do this with sql, while as an option - a preliminary enumeration and array processing is not a very good option.
Answer the question
In order to leave comments, you need to log in
First, the tables must be linked by relations. Those. they must be written in the models. I hope you have done this.
And then everything should be easy, something like:
$rooms=Room::model()->with('tarif')->findAll(array(
'order'=>'tarif.price_small'
));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question