diff options
author | David Jones <dgjones@gmail.com> | 2012-05-15 09:40:24 -0700 |
---|---|---|
committer | David Jones <dgjones@gmail.com> | 2012-05-15 09:40:24 -0700 |
commit | e2322a9087d7eb5dc78b72c6ffacfe55a50b8c9e (patch) | |
tree | 7d3b1631add9ba011f9dae26e9dc2e933f672b52 /guides | |
parent | ceafd7626da7af11359a685b66e58268b8ab4f5b (diff) | |
download | rails-e2322a9087d7eb5dc78b72c6ffacfe55a50b8c9e.tar.gz rails-e2322a9087d7eb5dc78b72c6ffacfe55a50b8c9e.tar.bz2 rails-e2322a9087d7eb5dc78b72c6ffacfe55a50b8c9e.zip |
Make the 'Using Models in Your Migrations' example code more concise by using update_all method
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/migrations.textile | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/guides/source/migrations.textile b/guides/source/migrations.textile index f855072fd8..52dba76e68 100644 --- a/guides/source/migrations.textile +++ b/guides/source/migrations.textile @@ -737,9 +737,7 @@ column. class AddFlagToProduct < ActiveRecord::Migration def change add_column :products, :flag, :boolean - Product.all.each do |product| - product.update_attributes!(:flag => false) - end + Product.update_all :flag => false end end </ruby> @@ -762,9 +760,7 @@ column. class AddFuzzToProduct < ActiveRecord::Migration def change add_column :products, :fuzz, :string - Product.all.each do |product| - product.update_attributes! :fuzz => 'fuzzy' - end + Product.update_all :fuzz => 'fuzzy' end end </ruby> @@ -816,9 +812,7 @@ class AddFlagToProduct < ActiveRecord::Migration def change add_column :products, :flag, :boolean Product.reset_column_information - Product.all.each do |product| - product.update_attributes!(:flag => false) - end + Product.update_all :flag => false end end </ruby> @@ -833,9 +827,7 @@ class AddFuzzToProduct < ActiveRecord::Migration def change add_column :products, :fuzz, :string Product.reset_column_information - Product.all.each do |product| - product.update_attributes!(:fuzz => 'fuzzy') - end + Product.update_all :fuzz => 'fuzzy' end end </ruby> |