Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should votes be it's own model in RoR app?

Let's say you want to create a Digg.com-like site. Should the votes be its own separate model, or should the votes be a field in the table for the model of the object that is voted on?

like image 928
Justin Meltzer Avatar asked Nov 28 '25 03:11

Justin Meltzer


2 Answers

It depends on how much information you want to store. If you just have a reference to something and a total score, then you don't need a model. If you have want to store who voted, how many up/down votes were received, timestamp when votes were received, and be able to rollback votes from unruly sources, then you'll need to keep each of those votes as their own model. Personally, I'd make each vote its own record, if I were designing such a system.

like image 104
Jarrett Meyer Avatar answered Nov 29 '25 17:11

Jarrett Meyer


Considering Digg.com-like site requirement, I would say - own model. Greatly due to the need of so called "voting rings" detection - detecting groups of fake voters.

Other than that - I would go with fields. MySQL for example can update rows atomically (so they say, never tried it myself), what is supposed to be quite efficient. More information on the MySQL docs.

like image 42
Tomek Kopczuk Avatar answered Nov 29 '25 19:11

Tomek Kopczuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!