Get a list/array of child classes from Single Table Inheritance in Rails?

后端 未结 7 771
礼貌的吻别
礼貌的吻别 2021-02-07 11:49

I have a whole bunch of child classes that inherit from a parent class via single-table-inheritance in my Rails app. I\'d like a way to get an array of all the child classes tha

7条回答
  •  你的背包
    2021-02-07 12:52

    Assuming there is at least one of each of object extant in the table:

    Object.all.uniq{|x| x.type}.collect(&:type)
    

提交回复
热议问题