Skip to content

Instantly share code, notes, and snippets.

@kjwierenga
Created November 2, 2009 15:55
Show Gist options
  • Save kjwierenga/224241 to your computer and use it in GitHub Desktop.
Save kjwierenga/224241 to your computer and use it in GitHub Desktop.
Entry.transaction do
Playlist.all.each do |playlist|
if positions_max = playlist.entries.maximum(:position)
ActiveRecord::Base.connection.execute("
UPDATE entries SET position = #{positions_max + 1} - position
WHERE playlist_id = #{playlist.id}")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment