0
我有一个配方应用程序,其中每个配方与许多配料相关联,并且配料使用ancestry宝石进行组织。Rails血统协会
class Ingredient < AR::Base
has_ancestry
has_many :recipe_ingredients
has_many :recipes, through: :recipe_ingredients
end
class Recipe < AR::Base
has_many :recipe_ingredients
has_many :ingredients, through: :recipe_ingredients
end
因此,例如,“酱油”将是一种成分,“kikkoman”将是“酱油”的孩子。一个食谱可能会要求“酱油”或专门叫出“kikkoman”的名字。
我希望能够通过祖先搜索食谱,所以如果我搜索“酱油”,它也会找到与孩子“kikkoman”的食谱。我如何用Rails的魔法来实现这一点?
因为我不需要祖先,所以我只使用了包含原料及其后代的成分.ubtree。 – 2014-10-30 18:35:08