Hi, Currently polymorphic_type field always use the class name of parent in case of STI. For example, ====class Attachment < ActiveRecord::Base belongs_to :attachable, :polymorphic => :true end class Asset < ActiveRecord::Base has_one :attachment, :as => :attachable end class Photo < Asset end class Video < Asset end ==== Here, attachable_type will always have value "Asset" in all the case, even for Photo and Video. In fact, it''ll be "Asset" even if the has_one association is defined in Photo/Video instead of Asset. This feels like a bug but then I was told it''s expected behavior. This makes something like http://pastie.caboo.se/75480 impossible. Also, it restricts the mining operations you can perform ( counting, grouping, etc.). It''d be great to know why it''s designed this way. I had submitted a patch anyways - http://dev.rubyonrails.org/ticket/8841 Thanks, Pratik -- http://m.onkey.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
I ran into this when I was doing some polymorphic/sti stuff, and it took me a while to find the documentation describing the solution[1]. I''m no expert, so please forgive me, but this wasn''t expected the behavior I expected, at least :) So, I''d be curious to hear why things were implemented this way as well. [1] http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html Thanks, - Trevor On Jul 2, 7:23 pm, Pratik <pratikn...@gmail.com> wrote:> > Currently polymorphic_type field always use the class name of parent > in case of STI. > > This feels like a bug but then I was told it''s expected behavior. This > makes something likehttp://pastie.caboo.se/75480impossible. Also, it > restricts the mining operations you can perform ( counting, grouping, > etc.).--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
I think it''s so you can join onto the correct table easily and without redundancy, since the child type no longer corresponds to anything in the schema. Evan On 7/3/07, Trevor Turk <trevorturk@gmail.com> wrote:> > I ran into this when I was doing some polymorphic/sti stuff, and it > took me a while to find the documentation describing the solution[1]. > I''m no expert, so please forgive me, but this wasn''t expected the > behavior I expected, at least :) > > So, I''d be curious to hear why things were implemented this way as > well. > > [1] http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html > > Thanks, > - Trevor > > On Jul 2, 7:23 pm, Pratik <pratikn...@gmail.com> wrote: > > > > Currently polymorphic_type field always use the class name of parent > > in case of STI. > > > > This feels like a bug but then I was told it''s expected behavior. This > > makes something likehttp://pastie.caboo.se/75480impossible. Also, it > > restricts the mining operations you can perform ( counting, grouping, > > etc.). > > > > >-- Evan Weaver Cloudburst, LLC --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---