Rails 3 queries

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

So I can achieve the desired behavior with the latest Arel:

  ingredients = Ingredient.arel_table

Recipe.joins(:ingredients).where(ingredients[:name].matches_any("%chips %", "%gravy%"))

Is this the cleanest way?

Not sure how I deluded my self into believing that worked, but it didn't.

I still can't figure out how to build this query.

Either Google doesn't want to be my friend or I'm asking the wrong question. Does anyone know of any blogs/tutorials that cover Rails 3 has_many :through queries?