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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to