1

I'm trying to add an order by to EVERY find in my app. Here's what I'm working with already, but I'm not sure how to inject my order by statement. Little help?

public function beforeFind($queryData) {
    if (Configure::read('id') !=0) {
        // Force all finds to only find stuff which is within the current domain id
        $queryData['conditions'][$this->alias . '.domain_id'] = Configure::read('id');
}
    return $queryData;
}

2 Answers 2

1

You can do something like

$queryData['order'] = array('field1', 'field2', 'field3 DESC');
2
  • Getting this error: Error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created' in order clause is ambiguous Jan 29, 2014 at 22:32
  • be more explicit with all of your fields in searches. 'Model.created' Jan 30, 2014 at 16:33
0

Got it!

    $queryData['order'] = array($this->alias.'.created DESC');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.