I am working on a database design case which is very flexible and not sure how to handle it properly or what kind of pattern this is.
This is a simplified version to illustrate the problem I have:
Entities
- Party
- Contract
- Damage
Relations
- A contract is always linked to a party (pretty easy)
- A damage must be linked to a party but can optionally be linked to a contract
So, the last relation is the problem here. Since our endpoint is an API and people could potentially send the guid of Party A and the guid of Contract Y which is linked to Party B.
Which then the damage is owned by either Party A or B and this shouldn't be possible. Could add a check when adding the damage to make sure Party == Contract.Party but it feels like I am fooling the relationship database.
I am unsure on how this problem is called and how to solve it.