Rails STI has_many STI children of one type

463 Views Asked by At

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!

1

There are 1 best solutions below

2
Kévin-DDR On BEST ANSWER

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'