Module: ClosureTree::NumericOrderSupport::GenericAdapter

Defined in:
lib/closure_tree/numeric_order_support.rb

Instance Method Summary collapse

Instance Method Details

#reorder_with_parent_id(parent_id, minimum_sort_order_value = nil) ⇒ Object


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/closure_tree/numeric_order_support.rb', line 57

def reorder_with_parent_id(parent_id, minimum_sort_order_value = nil)
  scope = model_class.
    where(parent_column_sym => parent_id).
    order(nulls_last_order_by)
  if minimum_sort_order_value
    scope = scope.where("#{quoted_order_column} >= #{minimum_sort_order_value}")
  end
  scope.each_with_index do |ea, idx|
    ea.update_order_value(idx + minimum_sort_order_value.to_i)
  end
end