File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed
activemodel/lib/active_model
activerecord/lib/active_record Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -247,12 +247,18 @@ module Dirty
247
247
248
248
def initialize_dup ( other ) # :nodoc:
249
249
super
250
+ @mutations_from_database = nil
251
+ end
252
+
253
+ def init_attributes ( other ) # :nodoc:
254
+ attrs = super
250
255
if other . persisted? && self . class . respond_to? ( :_default_attributes )
251
- @attributes = self . class . _default_attributes . map do |attr |
252
- attr . with_value_from_user ( @attributes . fetch_value ( attr . name ) )
256
+ self . class . _default_attributes . map do |attr |
257
+ attr . with_value_from_user ( attrs . fetch_value ( attr . name ) )
253
258
end
259
+ else
260
+ attrs
254
261
end
255
- @mutations_from_database = nil
256
262
end
257
263
258
264
def as_json ( options = { } ) # :nodoc:
Original file line number Diff line number Diff line change @@ -525,12 +525,7 @@ def init_with_attributes(attributes, new_record = false) # :nodoc:
525
525
526
526
##
527
527
def initialize_dup ( other ) # :nodoc:
528
- @attributes = @attributes . deep_dup
529
- if self . class . composite_primary_key?
530
- @primary_key . each { |key | @attributes . reset ( key ) }
531
- else
532
- @attributes . reset ( @primary_key )
533
- end
528
+ @attributes = init_attributes ( other )
534
529
535
530
_run_initialize_callbacks
536
531
@@ -542,6 +537,18 @@ def initialize_dup(other) # :nodoc:
542
537
super
543
538
end
544
539
540
+ def init_attributes ( _ ) # :nodoc:
541
+ attrs = @attributes . deep_dup
542
+
543
+ if self . class . composite_primary_key?
544
+ @primary_key . each { |key | attrs . reset ( key ) }
545
+ else
546
+ attrs . reset ( @primary_key )
547
+ end
548
+
549
+ attrs
550
+ end
551
+
545
552
# Populate +coder+ with attributes about this record that should be
546
553
# serialized. The structure of +coder+ defined in this method is
547
554
# guaranteed to match the structure of +coder+ passed to the #init_with
You can’t perform that action at this time.
0 commit comments