diff options
| -rw-r--r-- | db/migrate/20150218175300_set_organisation_id_to_rps.rb | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/db/migrate/20150218175300_set_organisation_id_to_rps.rb b/db/migrate/20150218175300_set_organisation_id_to_rps.rb index 8572a5894..024f5938e 100644 --- a/db/migrate/20150218175300_set_organisation_id_to_rps.rb +++ b/db/migrate/20150218175300_set_organisation_id_to_rps.rb @@ -1,19 +1,13 @@ class SetOrganisationIdToRps < ActiveRecord::Migration - class RuleParameterSet < ActiveRecord::Base - attr_accessor :referential_id - attr_accessor :organisation_id - attr_accessor :name - end def up - RuleParameterSet.all.each_with_index do |rps, index| - rps.update_attributes :organisation_id => Referential.find( rps.referential_id).organisation_id, - :name => "{rps.name} {index}" - end + RuleParameterSet.where(organisation_id: nil).update_all "name = concat(name, ' ', id)" + + # RuleParameterSet.joins(...).update_all("organisation_id = referentials.organisation_id") + # fails (see https://github.com/rails/arel/pull/294) + execute "UPDATE rule_parameter_sets SET organisation_id = referentials.organisation_id FROM referentials WHERE referentials.id = rule_parameter_sets.referential_id;" end def down - RuleParameterSet.all.each_with_index do |rps, index| - rps.update_attributes :organisation_id => nil - end + RuleParameterSet.update_all organisation_id: nil end end |
