Yii:相关表格的默认排序模型

Yii:相关表格的默认排序模型

问题描述:

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 findByPk() on a house and have the associated pets sorted by species then name?

Hendersons
--------------
Cat "Hairball"
Cat "Princess"
Dog "Ace"
Dog "Killer"

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

我有三个表,“宠物”,“物种”和“家园”。 家里有多只宠物,每只宠物都有一种。 这个物种可以在一个家里混合。 p>

是否可以在房子上使用 findByPk() code>并按照物种分类相关的宠物然后命名?

  Hendersons 
 -------------- 
Cat“Hairball”
Cat“Princess”
Dog“Ace”
Dog“Killer”  
  code>  pre> 
 
 

这对某人来说可能是显而易见的,但我找不到答案。 p> div>

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

'pets' => array(self::MANY_MANY, 'Pets', 'home_id',
                'order'=>'species.name ASC',
                'with'=>'species')

Pretty simple. Thanks, Carlos.