crowhill crowhill - 1 year ago 107
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download