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

后端 未结 7 858
礼貌的吻别
礼貌的吻别 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:42

    You need to eager load the classes, as stated in: https://github.com/rails/rails/issues/3364

    ActionDispatch::Reloader.to_prepare do
      Rails.application.eager_load!
    end
    

    Then you will be able to use:

    YourClass.subclasses
    

    or

    YourClass.descendants
    

提交回复
热议问题