I have three relations, user, shopping_list and item. Users can have multiple shopping lists and shopping lists hold multiple items. The rule is that a shopping list can only hold one kind of item, like one "tv" for example.
On my webpage i have a spot where the user can select which shopping_list he/she would like to add the item too. The shopping lists appear in a drop down and the user selects it. It works fine but it does not follow the rule mentioned above. I would like to not show the shopping list if it already holds that item but continue to show the rest.
Here are my relations
create_table "shopping_lists", force: true do |t|
t.integer "user_id"
t.integer "list_id"
t.string "name"
end
create_table "item", force: true do |t|
t.integer "list_id"
t.integer "item_id"
end
How do i build my query so that when i am on a page i only get shopping lists that do not already hold that item?
(I thought about adding a user_id to the 'item' relation and then i could use the '-' operator, i'm not sure how that works in rails. do you think that would be the way to go?)