Question

I have a belongsTo array in my gal_provider model as below:

var $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => 'User.name'
        ),
 )

And most of the functions inluded in the model gal_provider requires to sort the results according to the user names. But there is a function called recevtProviders() does not require this order. So I tried

$order = "";
$gal_providers = $this->find("all",array("conditions"=>$conditions,"recursive"=>$recursive,
            "fields"=>$fields,"limit"=>$limit,"order"=>$order));

BUt the query generated still shows ORDER BY "User.name". How can I disable this order only from this function?

Was it helpful?

Solution

I believe the order parameter you're passing is only going to affect the gal_provider model. Try this just before your find call to remove the order from the associated model:

$this->belongsTo['User']['order'] = '';

Also, if you're not using it, Containable is a very useful behavior. Using containable, the order on the User model could be disabled like this:

$this->find("all",array("conditions"=>$conditions,"recursive"=>$recursive,
            "fields"=>$fields,"limit"=>$limit,"order"=>$order,"contain" => array("User" => array("order" => ""))));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top