I have the following models:
class Recipe < ActiveRecord::Base has_many :ingredient_amounts has_many :ingredients, :through => :ingredient_amounts end
class Ingredient < ActiveRecord::Base def self.named_like(name) where('ingredients.name ILIKE ?', "%#{name}%") end end
How do I query for all the recipes that include the ingredients "chips" and "gravy".
I've tried:
Recipe.joins(:ingredients) & Ingredient.named_like("chips") & Ingredient.named_like("gravy")
but that gives me recipes that include ingredients with names that include both "chips" and "gravy" (e.g. named "gravy chips" or "spicy chips with gravy", etc)
Thanks in advance, Bryan