E
E
EVOSandru62015-12-01 04:53:46
Yii
EVOSandru6, 2015-12-01 04:53:46

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

1 answer(s)
N
newpy, 2015-12-04
@EVOSandru6

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'
));

Look in the documentation www.yiiframework.com/doc/guide/1.1/en/database.arr. There are ready-made pieces of code that you can use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question