After some desperating waste of hours, I've found (¿?) a solution

Instead of paginate the Robot model, I paginate the Rating model
containing Robot:

$this->paginate = array('Rating' =>
        array('fields' => array('AVG(Rating.rating) AS range_avg',
'Robot.*'),
                'conditions' => array('Rating.created >' => date('Y-m-d', 
strtotime
("-1 week"))),
                'limit' => 10,
                'group' => array('Rating.robot_id'),
                'order' => array('range_avg' => 'desc'),
                'contain' => array('Robot')));

The resulting query works fine and I have my robots sorted by their
range_avg, but a problem solved implies new wild problems: the
paginator does'nt paginate anything. Im my view i have

$nav_pags = $paginator->prev('<<', null, '').' '.$paginator->numbers
();
$nav_pags .= ' '.$paginator->next('>>', null, '').'<br />';

but nav_pags is empty.

I've considered override the paginate method as said in the custom
query part of the doc, but in the same view I want to show the robots
filtered by average ratings (avg) or number of uses (count), and can
not override the method twice.

Suggestions?

Sorry for possible english mistakes.

On Mar 10, 12:51 pm, Xoubaman <xouba...@gmail.com> wrote:
> Instead of putting here a bunch of code of my own, I'll ask you to
> tell me the way you'd manage this:
>
> Robot hasMany Rating
> Robot has many other models linked.
>
> Robot has some fields with info.
> Rating has id, rating (integer), user_id and created
>
> I want to paginate all robots' fields with their average rating from a
> week to now without quering any other model than Rating.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to