comparison db/migrate/078_add_custom_fields_position.rb @ 1526:404aa68d4227

Merge from live branch
author Chris Cannam
date Thu, 11 Sep 2014 12:46:20 +0100
parents 261b3d9a4903
children
comparison
equal deleted inserted replaced
1493:a5f2bdf3b486 1526:404aa68d4227
1 class AddCustomFieldsPosition < ActiveRecord::Migration 1 class AddCustomFieldsPosition < ActiveRecord::Migration
2 def self.up 2 def self.up
3 add_column(:custom_fields, :position, :integer, :default => 1) 3 add_column(:custom_fields, :position, :integer, :default => 1)
4 CustomField.find(:all).group_by(&:type).each do |t, fields| 4 CustomField.all.group_by(&:type).each do |t, fields|
5 fields.each_with_index do |field, i| 5 fields.each_with_index do |field, i|
6 # do not call model callbacks 6 # do not call model callbacks
7 CustomField.update_all "position = #{i+1}", {:id => field.id} 7 CustomField.update_all "position = #{i+1}", {:id => field.id}
8 end 8 end
9 end 9 end