diff --git a/app/models/step_orderable_element.rb b/app/models/step_orderable_element.rb index 8ae60c3dd..ea47f3422 100644 --- a/app/models/step_orderable_element.rb +++ b/app/models/step_orderable_element.rb @@ -23,7 +23,10 @@ class StepOrderableElement < ApplicationRecord def decrement_following_elements_positions step.with_lock do yield - step.step_orderable_elements.where('position > ?', position).find_each do |step_orderable_element| + step.step_orderable_elements + .where('position > ?', position) + .order(position: :asc).each do |step_orderable_element| + # find_each ignore any ordering step_orderable_element.position -= 1 step_orderable_element.save! end