mirror of
https://github.com/redmine/redmine.git
synced 2025-11-14 01:06:00 +01:00
awesome_nested_set: import git 2-1-stable branch revision 8eaab19868f326 (#6579)
https://github.com/collectiveidea/awesome_nested_set/commit/8eaab19868f326 git-svn-id: http://svn.redmine.org/redmine/trunk@13145 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -51,6 +51,10 @@ module CollectiveIdea #:nodoc:
|
|||||||
connection.quote_column_name(order_column)
|
connection.quote_column_name(order_column)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quoted_order_column_full_name
|
||||||
|
"#{quoted_table_name}.#{quoted_order_column_name}"
|
||||||
|
end
|
||||||
|
|
||||||
def quoted_left_column_full_name
|
def quoted_left_column_full_name
|
||||||
"#{quoted_table_name}.#{quoted_left_column_name}"
|
"#{quoted_table_name}.#{quoted_left_column_name}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ module CollectiveIdea #:nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def nested_set_scope(options = {})
|
def nested_set_scope(options = {})
|
||||||
options = {:order => quoted_order_column_name}.merge(options)
|
options = {:order => quoted_order_column_full_name}.merge(options)
|
||||||
|
|
||||||
order(options.delete(:order)).scoped options
|
order(options.delete(:order)).scoped options
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ module CollectiveIdea #:nodoc:
|
|||||||
# update lefts and rights for remaining nodes
|
# update lefts and rights for remaining nodes
|
||||||
update_siblings_for_remaining_nodes
|
update_siblings_for_remaining_nodes
|
||||||
|
|
||||||
|
# Reload is needed because children may have updated their parent (self) during deletion.
|
||||||
|
reload
|
||||||
|
|
||||||
# Don't allow multiple calls to destroy to corrupt the set
|
# Don't allow multiple calls to destroy to corrupt the set
|
||||||
self.skip_before_destroy = true
|
self.skip_before_destroy = true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ module CollectiveIdea
|
|||||||
def no_duplicates_for_columns?
|
def no_duplicates_for_columns?
|
||||||
[quoted_left_column_full_name, quoted_right_column_full_name].all? do |column|
|
[quoted_left_column_full_name, quoted_right_column_full_name].all? do |column|
|
||||||
# No duplicates
|
# No duplicates
|
||||||
select("#{scope_string}#{column}, COUNT(#{column})").
|
select("#{scope_string}#{column}, COUNT(#{column}) as _count").
|
||||||
group("#{scope_string}#{column}").
|
group("#{scope_string}#{column}").
|
||||||
having("COUNT(#{column}) > 1").
|
having("COUNT(#{column}) > 1").
|
||||||
first.nil?
|
first.nil?
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ module CollectiveIdea #:nodoc:
|
|||||||
|
|
||||||
lock_nodes_between! a, d
|
lock_nodes_between! a, d
|
||||||
|
|
||||||
nested_set_scope.where(where_statement(a, d)).
|
nested_set_scope.where(where_statement(a, d)).update_all(
|
||||||
update_all(conditions(a, b, c, d))
|
conditions(a, b, c, d)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@@ -44,11 +45,23 @@ module CollectiveIdea #:nodoc:
|
|||||||
end
|
end
|
||||||
|
|
||||||
def conditions(a, b, c, d)
|
def conditions(a, b, c, d)
|
||||||
[
|
_conditions = case_condition_for_direction(:quoted_left_column_name) +
|
||||||
case_condition_for_direction(:quoted_left_column_name) +
|
|
||||||
case_condition_for_direction(:quoted_right_column_name) +
|
case_condition_for_direction(:quoted_right_column_name) +
|
||||||
case_condition_for_parent,
|
case_condition_for_parent
|
||||||
{:a => a, :b => b, :c => c, :d => d, :id => instance.id, :new_parent => new_parent}
|
|
||||||
|
# We want the record to be 'touched' if it timestamps.
|
||||||
|
if @instance.respond_to?(:updated_at)
|
||||||
|
_conditions << ", updated_at = :timestamp"
|
||||||
|
end
|
||||||
|
|
||||||
|
[
|
||||||
|
_conditions,
|
||||||
|
{
|
||||||
|
:a => a, :b => b, :c => c, :d => d,
|
||||||
|
:id => instance.id,
|
||||||
|
:new_parent => new_parent,
|
||||||
|
:timestamp => Time.now.utc
|
||||||
|
}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user