title: ActiveRecord, has_many :through, and Polymorphic Associations
body: <p>Folks,</p>
  
  <p>Want to make sure I understand this correctly. And please disregard the case for inheritance here (SentientBeing), trying to instead focus on polymorphic models in has_many :through relationships. That said, consider the following...</p>
  
  <pre><code>class Widget &lt; ActiveRecord::Base
    has_many :widget_groupings
  
    has_many :people, :through =&gt; :widget_groupings, :source =&gt; :person, :conditions =&gt; "widget_groupings.grouper_type = 'Person'"
    has_many :aliens, :through =&gt; :widget_groupings, :source =&gt; :alien, :conditions =&gt; "video_groupings.grouper_type = 'Alien'"
  end
  
  class Person &lt; ActiveRecord::Base
    has_many :widget_groupings, :as =&gt; grouper
    has_many :widgets, :through =&gt; :widget_groupings
  end
  
  class Alien &lt; ActiveRecord::Base
    has_many :widget_groupings, :as =&gt; grouper
    has_many :widgets, :through =&gt; :widget_groupings  
  end
  
  class WidgetGrouping &lt; ActiveRecord::Base
    belongs_to :widget
    belongs_to :grouper, :polymorphic =&gt; true
  end
  </code></pre>
  
  <p>In a perfect world, I'd like to, given a Widget and a Person, do something like:</p>
  
  <pre><code>widget.people &lt;&lt; my_person
  </code></pre>
  
  <p>However, when I do this, I've noticed the 'type' of the 'grouper' is always null in widget_groupings. However, if I to something like the following:</p>
  
  <pre><code>widget.widget_groupings &lt;&lt; WidgetGrouping.new({:widget =&gt; self, :person =&gt; my_person}) 
  </code></pre>
  
  <p>Then all works as I would have normally expected. I don't think I've ever seen this occur with non polymorphic associations and just wanted to know if this was something specific to this use case or if I'm potentially staring at a bug.</p>
  
  <p>Thanks for any help!</p>