我的相关模型如下:
GrandParent
has_many :kids
has_many :grand_children, through: :kids
Kid
belongs_to :grand_parent
has_many :grand_kids
GrandKid
belongs_to :kid
我只想在一个对象上调用.descendants,并获取属于其' lineage'的所有对象。
我认为使用祖先gem会给我我想要的.descendants方法,但它只会在单个类上创建一个额外的索引,允许你在所述类中获得后代。(非常适合注释和回复之类的东西) ,但对我的问题没用。)我的代码并不是真正理解问题的必要条件,但这里是针对那些感兴趣的人:https://gist.github.com/bjlinville1/8425bfe88bc7060209e8