views:

51

answers:

1

Trying to implement a rating system of users and postings.

What is the best schema for managing the multiple reputations.

A user has a reputation derived from postings and feedback(similar to SO).

Postings have a reputation too (again similar to SO).

My initial idea as to have one reputation table. The rows would correspond to the id of the user/posting and the value of the vote.

Two Questions:

  • Is this the best way of managing this?

  • The unique Ids of the user and posting records are auto incremented, the default value that rake would create. Seems like there is a possibility the unique_ids could collide. Is that valid concern? How could I mitigate this?

Thanks

+2  A: 

I would have separate tables for the post reputation and user reputations. These are semantically different things and should be separated as such.

This way you can have one table which has a foreign key to the post, and the other with a foreign key to the user for which the reputation is applicable.

ghills
seems like there is a lot of duplicated code though. Suggestions on that?
cbrulak
if the two tables have the same 'shape' won't your reputation processing code not care? In .Net you'd have to write up some interfaces but it would still work. Not sure of how to do that in ruby is but I would think it is possible
Joshua
Perhaps inheritance is where you should look. See http://api.rubyonrails.org/classes/ActiveRecord/Base.html and the section on 'Single Table Inheritance'You may have a little extra code but you shouldn't have to duplicate code, and from a DB standpoint it will be more normalized.
ghills