diff options
author | Lauro Caetano <laurocaetano1@gmail.com> | 2014-04-23 23:51:00 -0300 |
---|---|---|
committer | Lauro Caetano <laurocaetano1@gmail.com> | 2014-05-20 23:26:51 -0300 |
commit | 4debc86bd329d31360272ed15459cde3b9af3a10 (patch) | |
tree | 2743821dedf9539da64989fc9e9e79b4e1405d75 /activerecord/test/cases/associations/belongs_to_associations_test.rb | |
parent | b17f6e6877162648936c32e62c58305861beaf70 (diff) | |
download | rails-4debc86bd329d31360272ed15459cde3b9af3a10.tar.gz rails-4debc86bd329d31360272ed15459cde3b9af3a10.tar.bz2 rails-4debc86bd329d31360272ed15459cde3b9af3a10.zip |
Fix polymorphic eager load with foreign_key as String.
The foreign_key could be `String` and just doing `owners_map[owner_key]`
could return `nil`.
To prevent this bug, we should `to_s` both keys if their types are
different.
Fixes #14734.
Diffstat (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index dc7314b450..9c92dc1141 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -570,6 +570,19 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert companies(:first_client).readonly_firm.readonly? end + def test_test_polymorphic_assignment_foreign_key_type_string + comment = Comment.first + comment.author = Author.first + comment.resource = Member.first + comment.save + + assert_equal Comment.all.to_a, + Comment.includes(:author).to_a + + assert_equal Comment.all.to_a, + Comment.includes(:resource).to_a + end + def test_polymorphic_assignment_foreign_type_field_updating # should update when assigning a saved record sponsor = Sponsor.new |