问题
I have many "Users" and each of them will have maximum of 5 "Services". The User should be able to Rate (0-5) on each Service. I would also like to persist the Avg Rating of the Users.
This is what I am thinking, but there could be a better way?
User
id | user_name | dob | ...
Service (Fixed number of Services)
id |service_description | service_code | avg_rating
Rating:
id | service_id | user_id | rating (0-5)
回答1:
I have created an E/R diagram to depict the way a multiple ratings system can be implemented. Note that I have used generic names for a lot of things.
回答2:
If you allow users to change their rating and want to track their changes, you could simply do so by adding a created_at
attribute to the Rating entity. In that way you allways know the current rating (last/highest timestamp) and you can also look up which changes the user did to his rating. A lot of database systems add this attribute by default, as well as the last_changed
attribute.
来源:https://stackoverflow.com/questions/24494063/er-model-of-user-ratings