@@ -453,6 +453,8 @@ def self.save_records(models, associations, acting_user, validate, save)
453453 elsif parent . class . reflect_on_association ( association [ :attribute ] . to_sym ) . collection?
454454 #puts ">>>>>>>>>> #{parent.class.name}.send('#{association[:attribute]}') << #{reactive_records[association[:child_id]]})"
455455 dont_save_list . delete ( parent )
456+
457+
456458 if reactive_records [ association [ :child_id ] ] &.new_record?
457459 dont_save_list << reactive_records [ association [ :child_id ] ]
458460 end
@@ -465,14 +467,14 @@ def self.save_records(models, associations, acting_user, validate, save)
465467 else
466468 #puts ">>>>ASSOCIATION>>>> #{parent.class.name}.send('#{association[:attribute]}=', #{reactive_records[association[:child_id]]})"
467469 parent . send ( "#{ association [ :attribute ] } =" , reactive_records [ association [ :child_id ] ] )
468-
469470 dont_save_list . delete ( parent )
470- if reactive_records [ association [ :child_id ] ] &.new_record? && parent . class . reflect_on_association ( association [ :attribute ] . to_sym ) . macro == :has_one
471+
472+ if parent . class . reflect_on_association ( association [ :attribute ] . to_sym ) . macro == :has_one &&
473+ reactive_records [ association [ :child_id ] ] &.new_record?
471474 dont_save_list << reactive_records [ association [ :child_id ] ]
472475 end
473476 end
474477 end if associations
475-
476478 # get rid of any records that don't require further processing, as a side effect
477479 # we also save any records that need to be saved (these may be rolled back later.)
478480
@@ -481,6 +483,7 @@ def self.save_records(models, associations, acting_user, validate, save)
481483 next true if record . frozen? # skip (but process later) frozen records
482484 next true if dont_save_list . include? ( record ) # skip if the record is on the don't save list
483485 next true if record . changed . include? ( record . class . primary_key ) # happens on an aggregate
486+ next true if record . persisted? # record may be have been saved as result of has_one assignment
484487 next false if record . id && !record . changed? # throw out any existing records with no changes
485488 # if we get to here save the record and return true to keep it
486489 op = new_models . include? ( record ) ? :create_permitted? : :update_permitted?
@@ -505,7 +508,6 @@ def self.save_records(models, associations, acting_user, validate, save)
505508 attributes [ model . class . primary_key ] = model [ model . class . primary_key ]
506509 [ reactive_record_id , model . class . name , attributes , messages ]
507510 end
508-
509511 # if we are not saving (i.e. just validating) then we rollback the transaction
510512
511513 raise ActiveRecord ::Rollback , 'This Rollback is intentional!' unless save
0 commit comments