I'm trying to draw database schema and struggling with inheritance. Let me tell with an example:
I have tables List and Item:
Table List{
id varchar [not null, pk]
parent_list_id varchar [ref: - List.id]
}
Table Item{
id varchar [not null, pk]
list_id varchar [ref: > List.id]
}
Table Rule{
id varchar [not null, pk]
list_id varchar [ref: > List.id]
item_id varchar [ref: > Item.id]
}
There can be multiple lists and they inherit their Rules from a upper List. A List can have multiple Items and multiple Rules and all Lists and Items that belong to a List should inherit their Rules from the parent List. Sub Lists and Items can also set their own Rules and in case of a List the Rules are inherited to their sub Lists.
An example:
- List_A
- Rule_A (set exclusively to List_A)
- Rule_B (set exclusively to List_A)
- List_B
- Rule_A (inherited)
- Rule_B (inherited)
- Rule_C (set exclusively to List_B)
- Item_A
- Rule_A (inherited)
- Rule_B (inherited)
- Rule_C (inherited)
- Rule_D (set exclusively to Item_A)
Now, this shouldn't be such a big problem, but I also need to be able to set rules active or inactive. I considered setting a boolean active to my Model Rule but I think there are problems with that approach. If I want to set Rule_A and Rule_B to be inactive for Item_A (they would still be active under List_A and List_B), that is a problem since my Rules would have a list_id referring to the List_A. I would be really grateful if someone had some suggestions how to handle this kind of inheritance, I'm a bit stuck here.