aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/migrations/using_models_in_migrations.txt
diff options
context:
space:
mode:
authorFrederick Cheung <frederick.cheung@gmail.com>2008-09-13 17:13:05 +0100
committerFrederick Cheung <frederick.cheung@gmail.com>2008-09-13 17:13:05 +0100
commit25fd841fe0f1d6f43019595a06aef6d825f5f4d1 (patch)
tree7fca8c85181fa118176c7a44ce5f7eef0639ca30 /railties/doc/guides/migrations/using_models_in_migrations.txt
parent7b9a5c112ef65f93d8c2dbd46356ade719239557 (diff)
downloadrails-25fd841fe0f1d6f43019595a06aef6d825f5f4d1.tar.gz
rails-25fd841fe0f1d6f43019595a06aef6d825f5f4d1.tar.bz2
rails-25fd841fe0f1d6f43019595a06aef6d825f5f4d1.zip
Final batch of corrections
Diffstat (limited to 'railties/doc/guides/migrations/using_models_in_migrations.txt')
-rw-r--r--railties/doc/guides/migrations/using_models_in_migrations.txt4
1 files changed, 3 insertions, 1 deletions
diff --git a/railties/doc/guides/migrations/using_models_in_migrations.txt b/railties/doc/guides/migrations/using_models_in_migrations.txt
index 2bedfdd69a..35a4c6fdfd 100644
--- a/railties/doc/guides/migrations/using_models_in_migrations.txt
+++ b/railties/doc/guides/migrations/using_models_in_migrations.txt
@@ -1,6 +1,8 @@
[[models]]
== Using Models In Your Migrations ==
-When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done but some caution should be observed. Consider for example a migration that uses the Product model to update a row in the corresponding table. Alice later updates the Product model, adding a new column and a validation on it. Bob comes back from holiday, updates the source and runs outstanding migrations with `rake db:migrate`, including the one that used the Product model. When the migration runs the source is up to date and so the Product model has the validation added by Alice. The database however is still old and so does not have that column and an error ensues.
+When creating or updating data in a migration it is often tempting to use one of your models. After all they exist to provide easy access to the underlying data. This can be done but some caution should be observed.
+
+Consider for example a migration that uses the Product model to update a row in the corresponding table. Alice later updates the Product model, adding a new column and a validation on it. Bob comes back from holiday, updates the source and runs outstanding migrations with `rake db:migrate`, including the one that used the Product model. When the migration runs the source is up to date and so the Product model has the validation added by Alice. The database however is still old and so does not have that column and an error ensues because that validation is on a column that does not yet exist.
Frequently I just want to update rows in the database without writing out the SQL by hand: I'm not using anything specific to the model. One pattern for this is to define a copy of the model inside the migration itself, for example: