crowhill crowhill - 10 months ago 57
PHP Question

Yii: default sort model by related table

I have a three tables, "pets", "species" and "homes." Homes have multiple pets, each of which has a species. The species can be mixed in a home.

Is it possible to use

on a house and have the associated pets sorted by species then name?

Cat "Hairball"
Cat "Princess"
Dog "Ace"
Dog "Killer"

This is probably blindingly obvious to someone, but I'm not finding an answer.


With Carlos' help, here's the functional code, in "homes" model:

'pets' => array(self::MANY_MANY, 'Pets', 'home_id',
                'order'=>' ASC',

Pretty simple. Thanks, Carlos.