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-11 14:02:45 +0100
committerFrederick Cheung <frederick.cheung@gmail.com>2008-09-11 14:02:45 +0100
commit5ad2bce12d91786486c7f476f06a5139e12046ff (patch)
treeb02981c19ce454f8e0e98e596096bc8aebf4081c /railties/doc/guides/migrations/using_models_in_migrations.txt
parentbb52108ce8fd11cfae52a9776d33788075d0a9a8 (diff)
downloadrails-5ad2bce12d91786486c7f476f06a5139e12046ff.tar.gz
rails-5ad2bce12d91786486c7f476f06a5139e12046ff.tar.bz2
rails-5ad2bce12d91786486c7f476f06a5139e12046ff.zip
Add an example
Diffstat (limited to 'railties/doc/guides/migrations/using_models_in_migrations.txt')
-rw-r--r--railties/doc/guides/migrations/using_models_in_migrations.txt2
1 files changed, 1 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 562571290a..2bedfdd69a 100644
--- a/railties/doc/guides/migrations/using_models_in_migrations.txt
+++ b/railties/doc/guides/migrations/using_models_in_migrations.txt
@@ -1,5 +1,5 @@
+[[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.
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: