DataMapper - Enum like options flag for Discriminator?
-
28-10-2019 - |
Question
I have recently started using DataMapper in a few projects & overall I think its just fantastic. But I have a question about using a particular aspect of it.
I know that if I have a model with an Enum property (property :whatev, Enum[ :foo, :bar ]
), I can call Model.whatev.options[:flag]
& get back all of the different possible values for the particular Enum. I am wondering if anyone knows (or could point me in the right direction) if there is something similar for the Discriminator
property type?
ie. is there a way to call that particular property & have it return the various options
Solution
A bit late, but here goes. Given model definitions such as:
class Foo
include DataMapper::Resource
property :id, Serial
property :type, Discriminator
end
class Bar < Foo; end
class Baz < Foo; end
You can see the subclasses with:
Foo.descendants.entries
which returns an array: [Bar, Baz]
.