Wednesday, November 7, 2012

Order by field containing aggregate function result (MIN)

Hi, I'm having trouble with sorting during pagination. I'm trying to list users with lowest solvetime, but order key in paginate method doesn't seem to like order field if it's a result of aggregate function like MIN().

This is my action:

public function index() {   
        $this->paginate = array(
            'fields' => array('*, MIN(Game.time AS mintime'),
            'conditions' => array('Game.time IS NOT NULL AND Game.visible = 1 AND Game.end_time IS NOT NULL AND Game.moves IS NOT NULL'),
            'order' => array('mintime' => 'ASC'),
            'group' => array('Game.uid'),
            'limit' => 3
        );
        $games = $this->paginate('Game');

        $this->set('games', $games);
    }

...it doesn't even add an ORDER BY clause in the debug. If some other field is set as order argument it works.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate