Basically I want to create a comment system where comments may have parents that are also comments BUT I would also like them to potentially have parents that may be something else, such as users or products (ie, I want to be able to comment on products, users, other comments, or practically any resource)
How should I do that?
Current tables:
tags, products, users, comments
edit - this would be for a somewhat high traffic site, so I can't have it doing all kinds of craziness :-)
4条答案
按热度按时间6pp0gazn1#
Do you want to have comments on products, users, reviews, etc? Or find the products, users, reviews, etc, that a comment is referring to?
For the former, I would have tables to associate things with their comments:
Where a comment_thread is just a reference to a thread that every comment references:
So every commentable entity in the system would have a join table and one comment_thread just waiting for eager users to add comments to. Or you could just link to a root comment instead and do without that indirection.
zphenhs42#
Your best bet would be isolating the comments from the targets. Something like...
Then tables like...
Where only the root comments (no parent) would have a row. This would allow you to still maintain a strong foreign-key architecture all around and still only be able to associate a comment to one product.
ryevplcw3#
my try:
this will allow for you to find them using an index, without too much waste with storage
mu0hgdu04#
maybe
In table_source you would save the table source (product, user, etc), and in row_source, the id of the row the comment is pointing.