Yeah, kinda dumb title, but I found it hard to describe my problem. I have the following tables:
properties
id | name
1 | color
2 | material
options
id | property_id | name
1 | 1 | yellow
2 | 1 | blue
3 | 2 | wood
4 | 2 | stone
substances
id | name
1 | orange juice
2 | cheese
relations
id | substance_id | option_id
1 | 2 | 1
2 | 2 | 3
3 | 1 | 1
Now, I have a list of options and want to know which substances are related to all those options. (For example, which substances are yellow and made of wood?) Is this possible with one query?
I'm trying to do this in Rails.