Sort elements from the HAS_MANY relation

Hi All

Suppose I have a model Company, which HAS_MANY employees:




'employees' 				=> array(self::HAS_MANY, 'Employee', 'companyid'),



So I can do:




$company = Company::model()->findByPk(101) ;

$employees = $company->employees ; // random order



No problems so var, but now I would like to influence the order of employees. For example, I want them to be order by salary

Any suggestions ?

Cheers

Luca

Hi Luca,

I think the easiest way would be to set up a relational query, as such:


$company = Company::model()->with(array(

'employees'=>array(

'order'=>'salary',

),

))->findByPk(101);

Hope that helps!

George

ok, thanks a lot!