How do product-review votes get modeled in the database?
I would like to know your thoughts on how to model votes for product reviews. If you have done any online shopping you might have noticed that many product reviews have an "x people out of x found this review helpful."
Assuming many customers will review many products, and many customers will vote on many reviews, is it best to have one table with totalVotes and helpfulVotes columns as such:
customerReviews(id, customerId, productId, reviewText, totalVotes, helpfulVotes)
Or have two tables, the second storing votes separately, as such:
customerReviews(id, customerId, productId, reviewText)
reviewVotes(id, reviewId, customerId, helpfull) (helpfull would be a 0,1 value)
Your thoughts are appreciated it. Another ass开发者_如何学运维umption here is that to vote a customer must be a member.
I really think that for most common use cases you don't need to persist who voted for a review, nor what particular votes had been cast. At most you would need to keep that in a session variable for usability reasons, letting the user change his vote for a limited time period.
This way you only need to keep a count per review, not per each customer:
review(id, productId, authorId, text, votes, helpfulCount)
This way there is no need to aggregate, sum, count or any other potentially costly operation, and things are simple. Simple is good.
I would put them all on the same table just to make things simple. It I've tried this before as well and that is how i went about it.
精彩评论