Skip to content

Commit d20e0c3

Browse files
committed
Preserve mutation changes when updating parent_id
1 parent c27057c commit d20e0c3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/closure_tree/hierarchy_maintenance.rb

+10
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,20 @@ def _ct_after_save
4242
rebuild!
4343
end
4444
if public_send(changes_method)[_ct.parent_column_name] && !@was_new_record
45+
tmp_previous_mutation_tracker = @previous_mutation_tracker
46+
tmp_mutation_tracker = @mutation_tracker
47+
tmp_mutations_from_database = @mutations_from_database
48+
tmp_mutations_before_last_save = @mutations_before_last_save
49+
4550
# Resetting the ancestral collections addresses
4651
# https://github.com/mceachen/closure_tree/issues/68
4752
ancestor_hierarchies.reload
4853
self_and_ancestors.reload
54+
55+
@previous_mutation_tracker = tmp_previous_mutation_tracker
56+
@mutation_tracker = tmp_mutation_tracker
57+
@mutations_from_database = tmp_mutations_from_database
58+
@mutations_before_last_save = tmp_mutations_before_last_save
4959
end
5060
@was_new_record = false # we aren't new anymore.
5161
@_ct_skip_sort_order_maintenance = false # only skip once.

0 commit comments

Comments
 (0)