mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make the 'Using Models in Your Migrations' example code more concise by using update_all method
This commit is contained in:
parent
ceafd7626d
commit
e2322a9087
1 changed files with 4 additions and 12 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue