(I recognize this is likely a duplicate, but I cannot find any answers based on searching)
I have a table with some information which can either join on a user, or on a company. There are three ways I see to solve this problem:
- Give the table a join_user_id column and a join_company_id column, and only fill in one of the two.
- Make a join_id column, and a joins_with_table column
- Duplicate the main table so that there are two versions, one with only a join_user_id, and one with only a join_company_id.
I'm ruling out 3 immediately because it's not dry. My question is, which of these is truly normalized design (or none of them)?
How do I handle the drawbacks of: 1. Leaving a bunch of empties, doesn't grow gracefully if a 3rd table comes, and how do I join succinctly? 2. How do I enforce foreign-key constraints? How do I join succinctly?