Oh yeah. I'm definitely keeping a rating field in each of the rateable models. The load from having to go through the vote table and count for every record would be ridiculous. A tiny bit of denormalization never hurt anyone.
One more thing though... Is it alright to leave the vote table denormalized? The thing is I either have to: 1) Use 1 votes table with the extra fields model, model_id, and model_field (for the vote field in that specific model since some votes have different names) 2) Normalize everything into distinct tables like publication_votes, issue_resolution_votes, ... I would get about 5 extra tables the second way, which would be a little annoying but possibly cleaner in the end. Any suggestions? On May 22, 9:26 am, number9 <[email protected]> wrote: > If you want to record all of that information then yes that would be > the best way to do it. > > A simpler method would be to give each publication an integer field, > and create two functions (vote_up/vote_down), I have attached sample > code below for vote_up function (vote down would be the same, but > rating would obviously be minus 1). > > // retreive id and store in a variable for use later on: > $publication_id = $this->Publication->read(null, $id); > // Retrieve "ratings" field, and add 1 to it: > $new_rating = $this->Publication->field('rating') + 1; > > // Now try and save the new ratings number, check if the ID exists > first: > if (!empty($publication_id)) { > // set flash message > $this->Publication->saveField('rating', $new_rating); > $this->Session->setFlash(__('Success! Thankyou for rating.', > true)); > > } else { > > // otherwise throw out error message: > $this->Session->setFlash('Sorry, we couldn\'t register that rating, > please try again.'); > > } > > You could probably use some of that even if you decide to use a > seperate table. If you do use a seperate table, countcache would be > worth looking into to count the number of votes (http:// > book.cakephp.org/view/816/counterCache-Cache-your-count). > > I've not been baking long, but I think this is correct, you will have > to excuse me if not! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
