I am having a little problem. I guess I also have a solution but not sure if it's a clean one.
Let's say I have a website with different objects: Person
, Product
Now users should be able to comment these, so I want another table for comments, but how should I tell my site whether the comment is for a person or product?
My solution: It would be a many-to-many relation, so I have a pivot table for the IDs. It would look like:
id
person_id
product_id
When the comment is for a person I would set the person_id
, and set the product_id
to NULL
... if it's a product i would set person_id
to NULL
.
Would that be a good way to do it? Are there any best practices for this kind of issue?