aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorYves Senn <yves.senn@garaio.com>2012-11-21 09:48:48 +0100
committerYves Senn <yves.senn@garaio.com>2012-11-22 15:08:17 +0100
commitd397a38c0268e61295e23f617e9bf70d905ea610 (patch)
treec40be8c2333aaba0928e41407e0fd2ac0442809c /activerecord/lib/active_record
parent4e00e8e91637e117f702ec277a5db1fd087cb347 (diff)
downloadrails-d397a38c0268e61295e23f617e9bf70d905ea610.tar.gz
rails-d397a38c0268e61295e23f617e9bf70d905ea610.tar.bz2
rails-d397a38c0268e61295e23f617e9bf70d905ea610.zip
backport #8291, prevent mass assignment of polymorphic type with `build`
Closes #8265 Conflicts: activerecord/CHANGELOG.md activerecord/lib/active_record/associations/association.rb
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/associations/association.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index 59c1bad559..ab0d888b16 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -231,7 +231,8 @@ module ActiveRecord
def build_record(attributes, options)
reflection.build_association(attributes, options) do |record|
- attributes = create_scope.except(*(record.changed - [reflection.foreign_key]))
+ skip_assign = [reflection.foreign_key, reflection.type].compact
+ attributes = create_scope.except(*(record.changed - skip_assign))
record.assign_attributes(attributes, :without_protection => true)
end
end