Table column reference to different tables

Options
Hello!
I want users to like & comment records from diffrent tables (like products, posts & offfers  etc)

What is the best DB design?
I think about this:

🔹c omments table has also columns: 
product_id (if comment left for product)
offer_id (if left for offer post BUT then product_id is empty)
post_id

and for each comment record there should be reference in one of these3 columns.


OR? maybe we have 1 column with reference to diffrent tables? i dont see it possible. 

Or please suggest how to do this correctly! 🙏
Thank you!

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    I think that method is fine if you want one comments table.

    You could also consider three separate comments table for each table they relate to.