I'm working on a standard relational database that stores options selected by users. I need to store some rules. What is the best way to architect this and keep it normalized?
Examples:
- If option A and option B are selected, option X must be selected.
- If option A and option B and option C are selected, option Y must be selected.
- If option D is selected, option Z cannot be selected.
- If option E and option F are selected, option Z cannot be selected.
I thought of something like this:
RequiredOptions Table
SelectedOption RequiredOption
A X
B X
A Y
B Y
C Y
ConflictingOptions Table
SelectedOption ConflictingOption
D Z
E Z
F Z
But one of the problems on the ConflictingOptions table is that if D is selected, it appears that that's allowed unless E and F are selected too. But that's not correct.
I thought about hashing the SelectedOption but wasn't sure if that was necessary.
RequiredOptions Table
SelectedOptionHash RequiredOption
Hash(A&B) X
Hash(A&B&C) Y
ConflictingOptions Table
SelectedOptionHash ConflictingOption
Hash(D) Z
Hash(E&F) Z
This wouldn't be very readable either.
I'm open to any suggestions. If anyone has experience or opinions they'd like to share, it would be greatly appreciated!