@@ -38,20 +38,38 @@ def _ct_after_save
3838      as_5_1  =  ActiveSupport . version  >= Gem ::Version . new ( '5.1.0' ) 
3939      changes_method  =  as_5_1  ? :saved_changes  : :changes 
4040
41-       if  public_send ( changes_method ) [ _ct . parent_column_name ]  || @was_new_record 
42-         rebuild! 
43-       end 
44-       if  public_send ( changes_method ) [ _ct . parent_column_name ]  && !@was_new_record 
45-         # Resetting the ancestral collections addresses 
46-         # https://github.com/mceachen/closure_tree/issues/68 
47-         ancestor_hierarchies . reload 
48-         self_and_ancestors . reload 
41+       if  public_send ( changes_method ) [ _ct . parent_column_name ] 
42+         _ct_persist_activerecord_state  do 
43+           if  @was_new_record 
44+             rebuild! 
45+           else 
46+             # Resetting the ancestral collections addresses 
47+             # https://github.com/mceachen/closure_tree/issues/68 
48+             ancestor_hierarchies . reload 
49+             self_and_ancestors . reload 
50+           end 
51+         end 
4952      end 
53+ 
5054      @was_new_record  =  false  # we aren't new anymore. 
5155      @_ct_skip_sort_order_maintenance  =  false  # only skip once. 
5256      true  # don't cancel anything. 
5357    end 
5458
59+     def  _ct_persist_activerecord_state  &block 
60+       tmp_previous_mutation_tracker  =  @previous_mutation_tracker 
61+       tmp_mutation_tracker  =  @mutation_tracker 
62+       tmp_mutations_from_database  =  @mutations_from_database 
63+       tmp_mutations_before_last_save  =  @mutations_before_last_save 
64+ 
65+       yield  block 
66+ 
67+       @previous_mutation_tracker  =  tmp_previous_mutation_tracker 
68+       @mutation_tracker  =  tmp_mutation_tracker 
69+       @mutations_from_database  =  tmp_mutations_from_database 
70+       @mutations_before_last_save  =  tmp_mutations_before_last_save 
71+     end 
72+ 
5573    def  _ct_before_destroy 
5674      _ct . with_advisory_lock  do 
5775        delete_hierarchy_references 
0 commit comments