Get the children associations for a given class, association name and
parent association. Much like the instance method of the same name, it will
return an empty array if no associations have the name, and only have
multiple association instances if the underlying relationship is
polymorphic.
Association.children(User, :pages, user_association)
def self.children(klass, assoc, parent=nil)
ref = klass.reflect_on_association(assoc)
return [] if ref.nil?
return [Association.new(parent, ref)] unless ref.options[:polymorphic]
polymorphic_classes(ref).collect { |poly_class|
Association.new parent, depolymorphic_reflection(ref, klass, poly_class)
}
end