I'm not sure if you've got this part sorted, but here is how I do
something similar in my app.

I have Films hasMany Ratings.

My films table has a field called "average_rating" which is updated
every time a new rating is added (whenever someone votes).

Here is a cutdown version of my Rating model.

<?php
class Rating extends AppModel {

        var $name = 'Rating';

        var $belongsTo = array(
                        'Film' => array('className' => 'Film', 'foreignKey' => 
'film_id')
        );

        // recalculate the average rating for the film
        function afterSave($created) {

                $average_rating = $this->field('AVG(rating)', array('film_id' =>
$this->data['Rating']['film_id']));
                $this->Film->save(array('id' => 
$this->data['Rating']['film_id'],
'average_rating' => $average_rating));

        }

}
?>


>From then on, you can use sort and display on Film.average_rating just
like any normal field.

Cheers,
Adam


On Dec 3, 4:40 am, "Dardo Sordi Bogado" <[EMAIL PROTECTED]> wrote:
> If you go to http://www.google.com, then in the search field you have
> to put "cakephp paginateCount", and here it comes:
>
> *http://bakery.cakephp.org/articles/view/new-cakephp-releases:
>
> >> Pagination flexibility has also been improved with the addition of
>
> Model::paginate(), and Model::paginateCount(), which you can define in
> your models to handle custom pagination. Each method takes the same
> parameters as findAll() and findCount(), respectively. <<
>
> 2007/12/1, Bram Duvigneau <[EMAIL PROTECTED]>:
>
>
>
> > Dardo Sordi Bogado wrote:
> > > Implement paginate() and paginateCount() in the model with your custom 
> > > querys
> > OK, but which parameters should be accepted by this functions? It seems
> > that these aren't even in the api...
>
> > Bram
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to