Following the AWDWR STI example (People, Employee, Manager, etc). If I
want to present a list of potential subclasses to add, and I plan on
extending the list of subclasses over time, what is the best way to
generate the subclass list?
For example, should I create a YAML file and parse that? Create a table
in the db and read that in? Or is there some other way to get that list
from ActiveRecord?
Alternatively you could just use a constant defined in the base class,
something like
SUBCLASSES = [Employee, Manager, Slave…]
and then refer to it using Person::SUBCLASSES
or perhaps prettier define a method in the base class
def subclasses
[Employee, Manager, Slave…]
end
Alternatively you could just use a constant defined in the base class,
something like
SUBCLASSES = [Employee, Manager, Slave…]
and then refer to it using Person::SUBCLASSES
or perhaps prettier define a method in the base class
def subclasses
[Employee, Manager, Slave…]
end
and then refer to it using Person.subclasses
OBJECT already supports sub_classes method. you can use it on any model
without defining hard-coded list.
OBJECT already supports sub_classes method. you can use it on any model
without defining hard-coded list.
If you look at the referenced thread you’ll see there are some
performance downsides to using Object#subclasses_of, which I think is
what you’re referring to…
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.