Sean Clark Hess wrote: > Any hint on what those SQL statements might be?
This UNTESTED code might get you off to a good start. conditions_hash = {:old_position => old_position, :new_position => new_position} if old_position > new_position MyModel.update_all('position = position + 1', ['position >= :new_position AND position < :old_position', conditions_hash) elsif old_position < new_position MyModel.update_all('position = position - 1', ['position <= :new_position AND position > :old_position', conditions_hash]) end #do nothing if old_position == new_position my_model.update_attribute :position, new_position You should also 'clean' new_position. If it is > the maximum position, then you should set it to the maximum position. If it is < 1 then you should set it to one. HTH --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---