aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-11-03 10:23:42 +0000
committerJon Leighton <j@jonathanleighton.com>2011-11-03 10:23:42 +0000
commitb4b178f7e9a00a0235574a773cdbc06fe856acaf (patch)
treed5617680e972962e78dd0a8e3fad19e208451d0f
parent982a0f37f5239527e9db9225b1dc7e42c6a98417 (diff)
downloadrails-b4b178f7e9a00a0235574a773cdbc06fe856acaf.tar.gz
rails-b4b178f7e9a00a0235574a773cdbc06fe856acaf.tar.bz2
rails-b4b178f7e9a00a0235574a773cdbc06fe856acaf.zip
Fix #3247.
Fixes creating records in a through association with a polymorphic source type.
-rw-r--r--activerecord/CHANGELOG8
-rw-r--r--activerecord/lib/active_record/associations/through_association.rb2
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb5
3 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 798d875034..698a337dcc 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -8,7 +8,7 @@
class User < ActiveRecord::Base
store :settings, accessors: [ :color, :homepage ]
end
-
+
u = User.new(color: 'black', homepage: '37signals.com')
u.color # Accessor stored attribute
u.settings[:country] = 'Denmark' # Any attribute, even if not specified with an accessor
@@ -37,6 +37,12 @@
[Aaron Christy]
+*Rails 3.1.2 (unreleased)*
+
+* Fix creating records in a through association with a polymorphic source type. [GH #3247]
+
+ [Jon Leighton]
+
*Rails 3.1.1 (October 7, 2011)*
* Add deprecation for the preload_associations method. Fixes #3022.
diff --git a/activerecord/lib/active_record/associations/through_association.rb b/activerecord/lib/active_record/associations/through_association.rb
index b347a94978..f95e5337c2 100644
--- a/activerecord/lib/active_record/associations/through_association.rb
+++ b/activerecord/lib/active_record/associations/through_association.rb
@@ -44,7 +44,7 @@ module ActiveRecord
join_attributes = {
source_reflection.foreign_key =>
records.map { |record|
- record.send(source_reflection.association_primary_key)
+ record.send(source_reflection.association_primary_key(reflection.klass))
}
}
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb
index b703c96ec1..2f4dd9e55c 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -825,4 +825,9 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
def test_explicitly_joining_join_table
assert_equal owners(:blackbeard).toys, owners(:blackbeard).toys.with_pet
end
+
+ def test_has_many_through_with_polymorphic_source
+ post = tags(:general).tagged_posts.create! :title => "foo", :body => "bar"
+ assert_equal [tags(:general)], post.reload.tags
+ end
end