I''m way back at Rails 2.3.5. I can move up to 2.3.11 if anyone thinks that will help. My problem is this: class Entity < ActiveRecord::Base belongs_to :item, :polymorphic => true end class Name < ActiveRecord::Base has_one :entity, :class_name => "Entity", :as => :item end class Team < Name end The has_one does not work. It searches for the base_class of item "Name" instead of the class "Team". I see where these is a "trick" where you can change item_type= in the documentation but that causes me other problems. I tried moving the has_one to Team but that didn''t change anything. Any suggestions? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 11, 10:33 pm, Perry Smith <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m way back at Rails 2.3.5. I can move up to 2.3.11 if anyone thinks > that will help. My problem is this: > > class Entity < ActiveRecord::Base > belongs_to :item, :polymorphic => true > end > > class Name < ActiveRecord::Base > has_one :entity, :class_name => "Entity", :as => :item > end > > class Team < Name > end > > The has_one does not work. It searches for the base_class of item > "Name" instead of the class "Team". I see where these is a "trick" > where you can change item_type= in the documentation but that causes me > other problems.What exactly is "not working" here? Polymorphic associations are designed to store the class that''s needed to retrieve the associated record - storing the STI subclass instead of the base would mean that the STI type was stored in *two* locations (both in the ''type'' field on the record, and in ''item_type'' on the associated Entity record) which is generally regarded as *bad*. Note that base-class finds still return objects of subclasses (this isn''t C++ :) ): Name.find(some_team_id) # => a Team object --Matt Jones -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
On 12 May 2011 03:33, Perry Smith <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> class Entity < ActiveRecord::Base > belongs_to :item, :polymorphic => true > end > > class Name < ActiveRecord::Base > has_one :entity, :class_name => "Entity", :as => :item > end > > class Team < Name > end > > The has_one does not work. It searches for the base_class of item > "Name" instead of the class "Team".What command are you executing when you get a problem with "it searching" - what searches? What SQL gets produced in the log file?> I see where these is a "trick" > where you can change item_type= in the documentation but that causes me > other problems.What problems?> I tried moving the has_one to Team but that didn''t change anything.hrmmm... that was my first thought... If you try to associate Name objects, does that work okay?> Any suggestions?A query: Why are you specifying the class_name? ... as far as I can see, it shouldn''t be necessary here (but shouldn''t cause a problem either...) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.