johan
2006-Oct-19 20:06 UTC
Polymorphic assc. uses base_class of object instead of class , Why?
Example: class User < ActiveRecord::Base end class Member < User has_one :blog, :as => :blogable end class Blog < ActiveRecrod::Base belongs_to :blogable, :polymorphic => true end The member.blog.blogable_type is ''User''. Does anybody know the reasoning for using the base_class instead of the class name of the object --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Mear
2006-Oct-19 22:25 UTC
Re: Polymorphic assc. uses base_class of object instead of class , Why?
johan wrote:> Example: > > class User < ActiveRecord::Base > end > > class Member < User > has_one :blog, :as => :blogable > end > > class Blog < ActiveRecrod::Base > belongs_to :blogable, :polymorphic => true > end > > The member.blog.blogable_type is ''User''. > Does anybody know the reasoning for using the base_class instead of the > class name of the objectThe STI/Polymorphic thing is a bit of a mess at the moment, as I understand it. This recent documentation patch: http://dev.rubyonrails.org/changeset/5259 contains some info that might help you for now. Chris --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Mear wrote:> The member.blog.blogable_type is ''User''. > Does anybody know the reasoning for using the base_class instead of the > class name of the objectThe reason is that the RDBMS needs to do joins on the actual table, which corresponds to the base class, not the non-existent STI child class. Evan -- 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 -~----------~----~----~----~------~----~------~--~---