의 3 동등한 :레일 다음과 같은 모델을 감안할 때 복잡한 SQL 쿼리
이class Recipe < ActiveRecord::Base
has_many :recipe_ingredients
has_many :ingredients, :through => :recipe_ingredients
end
class RecipeIngredient < ActiveRecord::Base
belongs_to :recipe
belongs_to :ingredient
end
class Ingredient < ActiveRecord::Base
end
가 어떻게 레일 3 Arel을 사용하여 다음 SQL 쿼리를 수행 할 수 있습니까?
SELECT * FROM recipes WHERE NOT EXISTS (
SELECT * FROM ingredients WHERE
name IN ('chocolate', 'cream') AND
NOT EXISTS (
SELECT * FROM recipe_ingredients WHERE
recipe_ingredients.recipe_id = recipes.id AND
recipe_ingredients.ingredient_id = ingredients.id))
조인을 사용하면 굴절시킬 수 있습니까? subselects 정말 두 가지 쿼리를 수행하고 루비, IMO를 사용하여 제외하고 "레일"방식으로 존재하지 않는다 –