Current implementation of polymorphic association: class Picture < ApplicationRecord belongs_to :imageable, polymorphic: true end class Employee < ApplicationRecord has_many :pictures, as: :imageable end class Product < ApplicationRecord has_many :pictures, as: :imageable end
This allows querying for pictures of employee & product. However, when querying for corresponding associations of picture records, we have to use an interface imageable. Issues Faced 1) Looking it from an application viewpoint, this layer of abstraction seems unfounded most of the times. 2) It also causes confusion when chaining queries as we are working on an abstraction layer & not sure what association type it refers to. Proposal I was wondering if we could simply look at (id + model name) in the record & provide the model name as association interface. eg: Picture.first.employee or Picture.last.product While it can be achieved using conditions in association definitions, I would like to know how the community feels about having it inside ActiveRecord itself? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.