Is there a way to find all Polymorphic models of a specific polymorphic type in Rails? So if I have Group, Event, and Project all with a declaration like:
has_many :assignments, :as => :assignable
Can I do something like:
Assignable.all
…or
BuiltInRailsPolymorphicHelper.all("assignable")
That would be nice.
Edit:
… such that Assignable.all returns [Event, Group, Product] (array of classes)
There is no direct method for this. I wrote this monkey patch for
ActiveRecord::Base.This will work for any class.
Now you can do the following: