Hey everyone, I have been working on some code lately that seems to be yielding some unexpected results. Basically, I have a class that is using single table inheritance for basic subclassing, and I wanted the base class to be able to use a polymorphic interface for connecting up the different classes of information generically using one table. here is a pastie of the example: http://pastie.caboo.se/207583 Am I doing something wrong? Is this a bug? looking for advice. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Xie Hanjian
2008-Jun-03 09:14 UTC
Re: STI / Polymorphic Association Issue (or possible bug)?
* Derek P. <derek-88kYAtoe8eYTx9n+QjaLhg@public.gmane.org> [2008-06-02 19:07:33 -0700]:> here is a pastie of the example: http://pastie.caboo.se/207583You should put the has_many in SubPost> > Am I doing something wrong? Is this a bug? looking for advice. > > Thanks! > > >-- jan=callcc{|jan|jan};jan.call(jan) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Xie, Actually, it doesn''t matter where the has_many lives. Due to inheritance, it is actually defined for both classes. I spoke with bitsweat on IRC about this behavior and it turns out its expected, and here is why: All STI-based interactions with polymorphic objects will refer to the base class of the STI, by design. But, if you actually load that object into memory and check its class, you''ll see that its actually lazy-loaded (via the classable_id) and becomes the proper class at runtime. Now, I don''t *love* this design, and frankly, it will make it much harder to deal with as far as filtering is concerned, but hey, at least it works. Thanks for the help though. - Derek On Jun 3, 2:14 am, Xie Hanjian <jan.h....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> * Derek P. <de...-88kYAtoe8eYTx9n+QjaLhg@public.gmane.org> [2008-06-02 19:07:33 -0700]: > > > here is a pastie of the example:http://pastie.caboo.se/207583 > > You should put the has_many in SubPost > > > > > Am I doing something wrong? Is this a bug? looking for advice. > > > Thanks! > > -- > jan=callcc{|jan|jan};jan.call(jan)--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---