Hello, 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? Thanks, Ryan Glover -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Glover wrote:> > Hello, > > 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? > > Thanks, > Ryan Glover >See this discussion: http://groups.google.co.uk/group/rubyonrails-talk/browse_thread/thread/475260e21167de9a/51721d1d1d9c9c50?lnk=st&q=inverse+base_class&rnum=1&hl=en#51721d1d1d9c9c50 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Elad Meidar - Creopolis.com
2006-Dec-30 22:24 UTC
Re: Best way to enumerate STI subclasses
> 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.subclassesOBJECT already supports sub_classes method. you can use it on any model without defining hard-coded list. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Elad Meidar - Creopolis.com wrote:> > >> 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. > > > > >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... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---