ActiveRecord,has_many:through和多态关联
民间, 想要确保我正确理解了这一点。并且请忽略此处继承的情况(SentientBeing),而尝试着眼于has_many:through关系中的多态模型。也就是说,请考虑以下事项... class Widget < ActiveRecord::Base has_many :widget_groupings has_many :people, :through => :widget_groupings, :source => :person, :conditions => "widget_groupings.grouper_type = 'Person'" has_many :aliens, :through => :widget_groupings, :source => :alien, :conditions => "video_groupings.grouper_type = 'Alien'" end class Person < ActiveRecord::Base has_many :widget_groupings, :as => grouper has_many :widgets, :through => :widget_groupings end …