我有这种关系
class Cupboard
include Mongoid::Document
field :name, type: String
has_many :ingredients
end
class Recipe
include Mongoid::Document
field :name, type: String
has_many :ingredients
end
class Ingredient
include Mongoid::Document
field :name, type: String
field :description, type: String
belongs_to :cupboard
belongs_to :recipe
end
我需要在橱柜模型中创建一个方法来查找包含与橱柜相同成分的食谱,我在 Mongoid 文档中找不到找到它的方法。
我需要类似的东西Recipe.find( #all cupboard.ingredients.ids )
提前致谢