Commit 6de768c417369ad9f4e18a6c733b83e074841515
Committed by
Larissa Reis
1 parent
23419734
Exists in
master
and in
29 other branches
custom-forms: update answers with the alternatives ids
Showing
1 changed file
with
12 additions
and
0 deletions
Show diff stats
plugins/custom_forms/db/migrate/20130823151900_associate_fields_to_alternatives.rb
@@ -14,6 +14,18 @@ class AssociateFieldsToAlternatives < ActiveRecord::Migration | @@ -14,6 +14,18 @@ class AssociateFieldsToAlternatives < ActiveRecord::Migration | ||
14 | end | 14 | end |
15 | end | 15 | end |
16 | 16 | ||
17 | + CustomFormsPlugin::Answer.find_each do |answer| | ||
18 | + labels = [] | ||
19 | + answer.value.split(',').each do |value| | ||
20 | + labels << answer.field.choices.invert[value] | ||
21 | + end | ||
22 | + labels.compact! | ||
23 | + if labels.present? | ||
24 | + answer.value = answer.field.alternatives.where('label IN (?)', labels).map(&:id).join(',') | ||
25 | + answer.save! | ||
26 | + end | ||
27 | + end | ||
28 | + | ||
17 | change_table :custom_forms_plugin_fields do |t| | 29 | change_table :custom_forms_plugin_fields do |t| |
18 | t.remove :choices | 30 | t.remove :choices |
19 | end | 31 | end |