CakePHP - 忽略$ hasMany模型中的订单 [英] CakePHP - Order in $hasMany model being ignored

查看:168
本文介绍了CakePHP - 忽略$ hasMany模型中的订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型有一个$ hasMany属性。如果我只有以下:

  var $ hasMany ='OtherModel'
/ pre>

并在类OtherModel中扩展AppModel我有以下:

  var $ order ='colour_id DESC'; 

订单被忽略,但如果我在第一个模型中有这个:

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

);

然后使用正确的顺序。



解决方案

模型的 $ order 属性只影响源自该特定模型的 find 调用。我想这是一个设计决定。您已经推出了对相关结果排序的正确方法。


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 instance?

解决方案

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.

这篇关于CakePHP - 忽略$ hasMany模型中的订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆