Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - Order in $hasMany model being ignored

Tags:

php

cakephp

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?

like image 694
going Avatar asked Apr 19 '10 22:04

going


1 Answers

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.

like image 110
Daniel Wright Avatar answered Sep 30 '22 01:09

Daniel Wright