@@ -51,6 +51,10 module CollectiveIdea #:nodoc: | |||||
51 | connection.quote_column_name(order_column) |
|
51 | connection.quote_column_name(order_column) | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
|
54 | def quoted_order_column_full_name | |||
|
55 | "#{quoted_table_name}.#{quoted_order_column_name}" | |||
|
56 | end | |||
|
57 | ||||
54 | def quoted_left_column_full_name |
|
58 | def quoted_left_column_full_name | |
55 | "#{quoted_table_name}.#{quoted_left_column_name}" |
|
59 | "#{quoted_table_name}.#{quoted_left_column_name}" | |
56 | end |
|
60 | end |
@@ -72,7 +72,7 module CollectiveIdea #:nodoc: | |||||
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def nested_set_scope(options = {}) |
|
74 | def nested_set_scope(options = {}) | |
75 | options = {:order => quoted_order_column_name}.merge(options) |
|
75 | options = {:order => quoted_order_column_full_name}.merge(options) | |
76 |
|
76 | |||
77 | order(options.delete(:order)).scoped options |
|
77 | order(options.delete(:order)).scoped options | |
78 | end |
|
78 | end |
@@ -19,6 +19,9 module CollectiveIdea #:nodoc: | |||||
19 | # update lefts and rights for remaining nodes |
|
19 | # update lefts and rights for remaining nodes | |
20 | update_siblings_for_remaining_nodes |
|
20 | update_siblings_for_remaining_nodes | |
21 |
|
21 | |||
|
22 | # Reload is needed because children may have updated their parent (self) during deletion. | |||
|
23 | reload | |||
|
24 | ||||
22 | # Don't allow multiple calls to destroy to corrupt the set |
|
25 | # Don't allow multiple calls to destroy to corrupt the set | |
23 | self.skip_before_destroy = true |
|
26 | self.skip_before_destroy = true | |
24 | end |
|
27 | end |
@@ -17,7 +17,7 module CollectiveIdea | |||||
17 | def no_duplicates_for_columns? |
|
17 | def no_duplicates_for_columns? | |
18 | [quoted_left_column_full_name, quoted_right_column_full_name].all? do |column| |
|
18 | [quoted_left_column_full_name, quoted_right_column_full_name].all? do |column| | |
19 | # No duplicates |
|
19 | # No duplicates | |
20 | select("#{scope_string}#{column}, COUNT(#{column})"). |
|
20 | select("#{scope_string}#{column}, COUNT(#{column}) as _count"). | |
21 | group("#{scope_string}#{column}"). |
|
21 | group("#{scope_string}#{column}"). | |
22 | having("COUNT(#{column}) > 1"). |
|
22 | having("COUNT(#{column}) > 1"). | |
23 | first.nil? |
|
23 | first.nil? |
@@ -24,8 +24,9 module CollectiveIdea #:nodoc: | |||||
24 |
|
24 | |||
25 | lock_nodes_between! a, d |
|
25 | lock_nodes_between! a, d | |
26 |
|
26 | |||
27 | nested_set_scope.where(where_statement(a, d)). |
|
27 | nested_set_scope.where(where_statement(a, d)).update_all( | |
28 |
|
|
28 | conditions(a, b, c, d) | |
|
29 | ) | |||
29 | end |
|
30 | end | |
30 |
|
31 | |||
31 | private |
|
32 | private | |
@@ -44,11 +45,23 module CollectiveIdea #:nodoc: | |||||
44 | end |
|
45 | end | |
45 |
|
46 | |||
46 | def conditions(a, b, c, d) |
|
47 | def conditions(a, b, c, d) | |
|
48 | _conditions = case_condition_for_direction(:quoted_left_column_name) + | |||
|
49 | case_condition_for_direction(:quoted_right_column_name) + | |||
|
50 | case_condition_for_parent | |||
|
51 | ||||
|
52 | # We want the record to be 'touched' if it timestamps. | |||
|
53 | if @instance.respond_to?(:updated_at) | |||
|
54 | _conditions << ", updated_at = :timestamp" | |||
|
55 | end | |||
|
56 | ||||
47 | [ |
|
57 | [ | |
48 | case_condition_for_direction(:quoted_left_column_name) + |
|
58 | _conditions, | |
49 | case_condition_for_direction(:quoted_right_column_name) + |
|
59 | { | |
50 | case_condition_for_parent, |
|
60 | :a => a, :b => b, :c => c, :d => d, | |
51 | {:a => a, :b => b, :c => c, :d => d, :id => instance.id, :new_parent => new_parent} |
|
61 | :id => instance.id, | |
|
62 | :new_parent => new_parent, | |||
|
63 | :timestamp => Time.now.utc | |||
|
64 | } | |||
52 | ] |
|
65 | ] | |
53 | end |
|
66 | end | |
54 |
|
67 |
General Comments 0
You need to be logged in to leave comments.
Login now