17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/closure_tree/numeric_order_support.rb', line 17
def reorder_with_parent_id(parent_id, minimum_sort_order_value = nil)
return if parent_id.nil? && dont_order_roots
min_where = if minimum_sort_order_value
"AND #{quoted_order_column} >= #{minimum_sort_order_value}"
else
''
end
connection.execute 'SET @i = 0'
connection.execute " UPDATE \#{quoted_table_name}\n SET \#{quoted_order_column} = (@i := @i + 1) + \#{minimum_sort_order_value.to_i - 1}\n WHERE \#{where_eq(parent_column_name, parent_id)} \#{min_where}\n ORDER BY \#{nulls_last_order_by}\n SQL\nend\n".squish
|