aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2015-11-16 12:43:59 -0600
committerSean Griffin <sean@seantheprogrammer.com>2015-11-16 12:43:59 -0600
commitbde974f418e2de7095fd6fd19c1e72b0c749fc30 (patch)
tree36beb89e311913c8619b03d3e0da2afcbe3e1804 /activerecord/lib
parent0f78936eac10f49e787658642ffec0b4abe6c9ef (diff)
parent817c1825c15013fd0180762ac5c05a2e024a640d (diff)
downloadrails-bde974f418e2de7095fd6fd19c1e72b0c749fc30.tar.gz
rails-bde974f418e2de7095fd6fd19c1e72b0c749fc30.tar.bz2
rails-bde974f418e2de7095fd6fd19c1e72b0c749fc30.zip
Merge pull request #22300 from yui-knk/fix_21893
Except keys of `build_record`'s argument from `create_scope` in initiā€¦
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/association.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/association.rb b/activerecord/lib/active_record/associations/association.rb
index c7b396f3d4..d64ab64c99 100644
--- a/activerecord/lib/active_record/associations/association.rb
+++ b/activerecord/lib/active_record/associations/association.rb
@@ -163,9 +163,12 @@ module ActiveRecord
@reflection = @owner.class._reflect_on_association(reflection_name)
end
- def initialize_attributes(record) #:nodoc:
+ def initialize_attributes(record, except_from_scope_attributes = nil) #:nodoc:
+ except_from_scope_attributes ||= {}
skip_assign = [reflection.foreign_key, reflection.type].compact
- attributes = create_scope.except(*(record.changed - skip_assign))
+ assigned_keys = record.changed
+ assigned_keys += except_from_scope_attributes.keys.map(&:to_s)
+ attributes = create_scope.except(*(assigned_keys - skip_assign))
record.assign_attributes(attributes)
set_inverse_instance(record)
end
@@ -248,7 +251,7 @@ module ActiveRecord
def build_record(attributes)
reflection.build_association(attributes) do |record|
- initialize_attributes(record)
+ initialize_attributes(record, attributes)
end
end