Let's say I have organization
and person
and they have a one-to-many
relationship with post
.
post
could only be owned by either an organization or user (person).
What I'm doing right now is making the foreign key nullable and adding a check constraint
to ensure only one of organization_id
and person_id
has a value and the other one is null
.
Is this considered a valid SQL
design (best practise)? What if I had more than two entities that could be the owner of a certain post?