开发者

CakePHP - Order in $hasMany model being ignored

开发者 https://www.devze.com 2022-12-27 05:35 出处:网络
I have one model that has a $hasMany attribute. If I just have the following: var $hasMany = \'OtherModel\'

I have one model that has a $hasMany attribute. If I just have the following:

var $hasMany = 'OtherModel'

and in the class OtherModel extends AppModel I have the following:

var $order = 'colour_id DESC';

The order is ignored, but if I have this in the first model:

    var $hasMany = array(
            'OtherModel' => array(
            'order' => 'colour_id DESC'
        )
    );

Then it uses the correct order.

I'm not sure why the order in the $hasMany model is ignored in the first in开发者_Python百科stance?


A model's $order property only affects find calls originating in that particular model. I suppose it is a design decision. You've already sussed out the correct method for sorting associated results.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号