36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/closure_tree/numeric_order_support.rb', line 36
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 " UPDATE \#{quoted_table_name}\n SET \#{quoted_order_column(false)} = t.seq + \#{minimum_sort_order_value.to_i - 1}\n FROM (\n SELECT \#{quoted_id_column_name} AS id, row_number() OVER(ORDER BY \#{order_by}) AS seq\n FROM \#{quoted_table_name}\n WHERE \#{where_eq(parent_column_name, parent_id)} \#{min_where}\n ) AS t\n WHERE \#{quoted_table_name}.\#{quoted_id_column_name} = t.id and\n \#{quoted_table_name}.\#{quoted_order_column(false)} is distinct from t.seq + \#{minimum_sort_order_value.to_i - 1}\n SQL\nend\n".squish
|