Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

[ActiveRecord 3.1.1] has_many :through with Polymorphic Associations seems broken #3423

Closed
abrisse opened this Issue Oct 24, 2011 · 1 comment

Comments

Projects
None yet
1 participant

abrisse commented Oct 24, 2011

Hi there.

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

module ExchangeManager
    module Resources
        class Chain < ActiveRecord::Base
            has_many :compositions
            has_many :tasks, :through => :compositions, :source => :link, :source_type => 'Task'
            has_many :chains, :through => :compositions, :source => :link, :source_type => 'Chain'
            has_many :parameters_interactions
            has_many :parameters, :as => :owner
        end
    end
end

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

I have just ugraded 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 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 `<main>'

abrisse commented Oct 24, 2011

Duplicate of #3247

@abrisse abrisse closed this Oct 24, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment