Im trying to figure out how to do a query in rails where with multiple ids returned from another query. I have a Food table that has_many compounds through contents. What Im trying to do is get a list of foods that share at least one compound with the original food. Currently I have the Following:
To get the compounds from the initial food i have this:
def set_food
@food = Food.includes(:compounds).find(params[:id])
end
This sets the food and compounds and i can output by calling each-do all the contents and show what compounds are in each food. So the next step im not sure how to do is how to get all the food_id's from the content table where compound_id equals one of the ones in the original content returned above (hopefully that makes sense). So something like this (i know this isnt right)
def show
@pairs = Food.joins(:contents).where(contents: {compound_id: @food.contents.compound_id})
end
Any help would be appreciated, tried googling answers but not even sure what to google to get in the right direction