Guardia Alata
2007-Feb-14 11:42 UTC
Single table inheritance and sub classes in subdirectories.
Hi everyone, I''m trying to organize my sources, according to the new 1.2 specifications. So, i''ve an Animal class, with some subclasses (Dog,Bird,Snake). Animal is in /model, the others in /models/animals. When i''ve to instantiate a Dog, doing something like Animals::Dog.new i''ve an exception: The single-table inheritance mechanism failed to locate the subclass: ''Dog''. This error is raised because the column ''type'' is reserved for storing the class in case of inheritance. (cut) This occurs why Rails is going to write just "Dog" in the type column, and not "Animals::Dog", so in the next call to the object the operation fails. I''m doing something messy or it''s just an issue? Thanks, alessio. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Hall
2007-Feb-14 13:00 UTC
Re: Single table inheritance and sub classes in subdirectories.
I looked in trac to see if there was a ticket for this and I couldn''t find one, although that doesn''t necessarily mean one doesn''t exist. If I were you, I would check out trac more thoroughly and if you can''t find anything related to it, open a ticket. be sure to include a test. My guess is that demodulize is getting called on the class name when it shouldn''t be. Also, if you were to replace the type from ''Dog'' to ''Animals::Dog'' in the database, it loads the record just fine. in the meantime, i would just put all your animal models in your main app/models directory, and change the class definitions from class Animals::Dog < Animal end to class Dog end On 2/14/07, Guardia Alata <guardiaalata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi everyone, > > I''m trying to organize my sources, according to the new 1.2 > specifications. > > So, i''ve an Animal class, with some subclasses (Dog,Bird,Snake). > > Animal is in /model, the others in /models/animals. > > When i''ve to instantiate a Dog, doing something like Animals::Dog.new > i''ve an exception: > > The single-table inheritance mechanism failed to locate the > subclass: ''Dog''. This error is raised because the column ''type'' is > reserved for storing the class in case of inheritance. (cut) > > This occurs why Rails is going to write just "Dog" in the type > column, and not "Animals::Dog", so in the next call to the object the > operation fails. > > I''m doing something messy or it''s just an issue? > > Thanks, > alessio. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---