ruby-on-railsactiverecordsingle-table-inheritancesti

Rails STI has_many STI children of one type


I've got a structure like so:

A holds one B (STI) which holds multiple C(STI)

How can I tell B1 (a sub class of B) that it holds multiple C1 (a subclass of C) if that's even possible. (B1 can only contain C1, no other C subclass)

Thanks!


Solution

  • I ended up finding a solution:

    I need to specify the class_name in has_many like so

    has_many :C, :foreign_key => :parent_id,  class_name: 'C::C1'