Hello,
I'm working on a project and I need some kind of dynamic compatibility matrix between items.
Let me explain using an abstract example
I have a table with all the items for that I want to set some compatibilities:
Table: Items (ItemID, ItemName):
1 | apple
2 | pear
3 | fistic
4 | ketch-up
5 | meat
6 | salad
7 | tomato
8 | ice-cream
9 | water
10 | cucumber
11 | peper
12 | salt
13 | soup
14 | roast
15 | sugar
Between these items I want to set up some dynamic compatibilities.
Let's say that I set the following compatibilities:
apple is compatible with: pear, fistic, salad, ice-cream, sugar.
sugar is compatible with: pear, salad
roast is compatible with: meat, peper, salt, sugar
soup is compatible with: tomato, peper, salt, meat, sugar.
Once I have this set up and trying to find out the compatibilities of meat I should find: roast, soup.
Also, the compatibilties of sugar should be: apple, pear, salad, roast, soup.
If I change the compatibilities of peper and remove soup, then the soup's compatibilities should be automatically updated to: tomato, peper, salt, meat.
My main issue is how to design the database for it.
My initial solution was to build a compatibilities table, like this:
Table: CompTable (ItemID, CompItemID):
1 | 2
1 | 3
1 | 6
1 | 8
1 | 15
15 | 2
15 | 6
14 | 5
14 | 11
14 | 12
14 | 15
13 | 7
13 | 11
13 | 12
13 | 5
13 | 15
But this solution is not dynamic. If I'm searching for sugar, I have to check for ItemID and also for CompItemID and then combine the results. - I don't want that...
Any help would be highly appreciated.
Thanks!