rails/rails — Issue #3423: [ActiveRecord 3.1.1] has_many :through with Polymorphic Associations seems broken
Author: abrisse
Created: 2011-10-24 16:40:59+00:00
State: open

Hi there.

I was using has_many :through with Polymorphic Associations with ActiveRecord 3.1.0 without any problem thanks to :

```ruby
class Widget < ActiveRecord::Base
has_many :widget_groupings

has_many :people, :through => :widget_groupings, :source => :grouper, :source_type => 'Person'
has_many :aliens, :through => :widget_groupings, :source => :grouper, :source_type => 'Alien'
end
```

The method is explained on http://stackoverflow.com/questions/1683265/activerecord-has-many-through-and-polymorphic-associations#1684492

I have just ugrade to Rails 3.1.1 and it doesn't work anymore. See stack below :

```
c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:1341:in `compute_type': uninitialized constant ExchangeManager::Res
ources::Composition::Link (NameError)
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/reflection.rb:173:in `klass'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/reflection.rb:228:in `association_primary_key'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/through_association.rb:47:in `block in construct_
join_attributes'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/through_association.rb:46:in `map'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/through_association.rb:46:in `construct_join_attr
ibutes'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/has_many_through_association.rb:54:in `through_re
cord'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/has_many_through_association.rb:45:in `insert_rec
ord'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:128:in `block (3 levels
) in concat'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:337:in `add_to_target'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:127:in `block (2 levels
) in concat'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:125:in `each'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:125:in `block in concat
'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:147:in `block in transa
ction'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `tr
ansaction'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/transactions.rb:208:in `transaction'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:146:in `transaction'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_association.rb:124:in `concat'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/has_many_through_association.rb:31:in `concat'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.1.1/lib/active_record/associations/collection_proxy.rb:118:in `<<'
from c:/Users/perfect-memory/dev/pm-platform/exchange-manager/spec/fixture_helper.rb:66:in `init'
from runner.rb:8:in `

'
```