很多时间,我们需要查询出来的结果按照指定的列进行索引,所以就会有了下面的代码

$lists = xxx::model('xx')->findAll(array('id'=>array(1,2,3,4,5)));//语句应该是不对的,表达我想in查询
然后
取出结果后
foreach($lists as $list){
$ls[$list->id]=$list;
}
这样有没有简化写法呢?因为我这样之后,发现。。。in查询变成了多条查询。
但是是lazy loading Xxxxx.xxx(relation中的关联)

有的,Yii中有类似的写法,那就是ar中的index(上文我刚说了on)

'index': the name of the column whose values should be used as keys of the array that stores related objects.

于是直接

$lists = xxx::model('xx')->findAll(array('index'=>'id'));

就OK了