Some input on relations needed

Hello!

How would you solve this problem? I'm using AR.

table a

table b

b belongs to a (HAS_ONE)

i want to select n amount of rows from b and order by column dateTime in table a.

And if i also would like to select some columns from table a in the same time, how would that command look like?

Thank you,

Martin



$bs=B::model()->with('a')->findAll(array('limit'=>$n, 'order'=>'a.dateTime'));


Note, you need to declare 'alias' option of relation 'a' to be 'a'.

Too easy!

Oh, and is it possible to use the select parameter in criteria, do i just specify the column with table prefix infront (eg. a.column) or am i limited to selecting all columns?

Sorry im unable to try this out for a while, thats why im asking and not testing myself.

Kudos!

Yes, you can pass a select key with a comma-separated string of fields. Make sure to use alias if there are ambiguous columns.

Quote

Yes, you can pass a select key with a comma-separated string of fields. Make sure to use alias if there are ambiguous columns.

Alrighty, thanks.