I don't know, < 1 ms seems like a good enough time for me. I'll think about "caching" the value in a column when I run into speed issues...
On 4 Sep 2008, at 21:13, Dardo Sordi Bogado wrote: > > Storing it in a column also makes the query faster. > > On Thu, Sep 4, 2008 at 8:32 AM, David C. Zentgraf <[EMAIL PROTECTED]> > wrote: >> >> I know this would be a lot easier for working with Cake, but the >> purist in me says it's just the wrong way to store the data. >> With raw SQL it's a no-brainer on how to make it work. >> I'm willing to wait for Cake to catch up to easily allow more >> complicated JOIN queries/conditions/order clauses, and the workaround >> in the meantime isn't that terrible... ;o) >> >> Chrs, >> Dav >> >> On 4 Sep 2008, at 19:35, Adam Royle wrote: >> >>> >>> I would add a "average_rating" field in your "places" tables, then >>> whenever you receive a rating, update the Places table... >>> >>> Here is some example code that I wrote for this site: >>> http://bigfish.tv/fest/ >>> >>> class Rating extends AppModel { >>> >>> var $belongsTo = array( >>> 'Film' => array('className' => 'Film', 'foreignKey' => >>> 'film_id') >>> ); >>> >>> >>> // recalculate the average rating for the film >>> function afterSave($created) { >>> >>> $rating_average = $this->field('AVG(rating)', array('film_id' => >>> $this->data['Rating']['film_id'])); >>> $this->Film->saveField(array('id' => $this->data['Rating'] >>> ['film_id'], 'rating_average' => $rating_average)); >>> >>> } >>> >>> } >>> >>> >>> On Sep 4, 5:57 pm, David Christopher Zentgraf <[EMAIL PROTECTED]> >>> wrote: >>>> Hi, >>>> >>>> I was wondering if anybody has thought about adding support for >>>> "manual sorting" to Cake. >>>> In my specific case, I need to paginate a model and want to order >>>> it >>>> by the average score of ratings that are stored in another table >>>> (Place hasMany Rating; ORDER BY AVG(Rating.score)). The best >>>> solution >>>> I found so far, next to writing my own paginator, was to add a >>>> condition like this to the paginate conditions: >>>> >>>> 1 = 1 ORDER BY FIELD(`Place`.`id`, 128, 97, ... ) DESC >>>> >>>> where I'm getting the list of ids in a separate query in the right >>>> order. >>>> This works fine, but since I don't like the "1 = 1 hack" I was >>>> wondering if there's a chance to get something like this into Cake: >>>> >>>> find('all', array('order' => array('Place.id' => array(1, 2, >>>> 3, ... )))); >>>> >>>> which would produce the above ORDER BY clause. I think that might >>>> come >>>> in handy in other situations as well. >>>> >>>> Chrs, >>>> Dav >>>> >> >> >>> >> > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" 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 -~----------~----~----~----~------~----~------~--~---
