@@ -38,20 +38,40 @@ 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+ _ct_persist_activerecord_state do
42+ if public_send ( changes_method ) [ _ct . parent_column_name ] || @was_new_record
43+ rebuild!
44+ end
45+
46+ if public_send ( changes_method ) [ _ct . parent_column_name ] && !@was_new_record
47+
48+ # Resetting the ancestral collections addresses
49+ # https://github.com/mceachen/closure_tree/issues/68
50+ ancestor_hierarchies . reload
51+ self_and_ancestors . reload
52+
53+ end
4954 end
55+
5056 @was_new_record = false # we aren't new anymore.
5157 @_ct_skip_sort_order_maintenance = false # only skip once.
5258 true # don't cancel anything.
5359 end
5460
61+ def _ct_persist_activerecord_state &block
62+ tmp_previous_mutation_tracker = @previous_mutation_tracker
63+ tmp_mutation_tracker = @mutation_tracker
64+ tmp_mutations_from_database = @mutations_from_database
65+ tmp_mutations_before_last_save = @mutations_before_last_save
66+
67+ yield block
68+
69+ @previous_mutation_tracker = tmp_previous_mutation_tracker
70+ @mutation_tracker = tmp_mutation_tracker
71+ @mutations_from_database = tmp_mutations_from_database
72+ @mutations_before_last_save = tmp_mutations_before_last_save
73+ end
74+
5575 def _ct_before_destroy
5676 _ct . with_advisory_lock do
5777 delete_hierarchy_references
0 commit comments