Permalink
Browse files

Fix #3247.

Fixes creating records in a through association with a polymorphic source
type.

Conflicts:

	activerecord/CHANGELOG
  • Loading branch information...
1 parent 7c36934 commit 01eae34d582b657f8a44941655edaeba33044d5c @jonleighton jonleighton committed Nov 3, 2011
View
@@ -1,3 +1,9 @@
+*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)*
* Raise an exception if the primary key of a model in an association is needed
@@ -44,7 +44,7 @@ def construct_join_attributes(*records)
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))
}
}
@@ -820,4 +820,9 @@ def test_preloading_empty_through_association_via_joins
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

0 comments on commit 01eae34

Please sign in to comment.