When dealing with polymorphic associations, is it possible to have a has_many through query that pulls in ALL available source_types?
My understanding so far is that each source type needs its own query method, as I show here in the Image model
has_many :image_tags has_many :tags, through: :image_tags, source: :taggable, source_type: 'Tag' has_many :people, through: :image_tags, source: :taggable, source_type: 'Person' has_many :businesses, through: :image_tags, source: :taggable, source_type: 'Business' ...
has_many :image_tags, as: :taggable has_many :images, through: :image_tags
belongs_to :image belongs_to :taggable, polymorphic: true def build_taggable(params) self.taggable = taggable_type.constantize.new(params) end
What I’d like to be able to do, however, is create one query method that pulls in all associated records regardless of what source_type they might belong to.
Just thinking out loud, would that likely involve creating some sort of raw SQL join that acts directly on the ImageTags table? Or is there a more Railsy/ActiveRecordy way of approaching it?
Thank you in advance for any help or insights!