ingredient.rb:
class Ingredient < ActiveRecord::Base
has_many :recipes, :through => :ingredients_with_quantities
has_many :ingredients_with_quantities
ingredient_with_quantity.rb:
class IngredientWithQuantity < ActiveRecord::Base
belongs_to :recipe
belongs_to :ingredient
recipe.rb:
class Recipe < ActiveRecord::Base
has_many :ingredients, :through => :ingredients_with_quantities
has_many :ingredients_with_quantities
I would like to make a query which get all recipes that includes a specific ingredient name.
Tried this query:
Recipe.find(:all, :include => {:ingredients_with_quantities => :ingredients}, :conditions => "ingredients.name = 'ingredient1'")
But I get this error:
NameError: uninitialized constant Recipe::IngredientsWithQuantity
Can someone tell me whats wrong with the query?
I can make a successfull query in SQL with:
SELECT r . * FROM recipes r, ingredient_with_quantities iq, ingredients i
WHERE i.name = "ingredient1"
AND iq.recipe_id = r.id
AND iq.ingredient_id = i.id
How does this query looks in Rails with ActiveRecord?
Thanks for helping me out!!
It is
:ingredient_with_quantitiesrather than:ingredients_with_quantities(you put a “s” afteringredient)