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