diff options
author | CassioMarques <cassiommc@gmail.com> | 2008-11-18 19:14:51 -0200 |
---|---|---|
committer | CassioMarques <cassiommc@gmail.com> | 2008-11-18 19:16:01 -0200 |
commit | b60971ad6b19a3cd72a972b459e94059d24c0848 (patch) | |
tree | f5b4ba2da11b06cd1844aa88ad53e5cb76dbe49b /railties/doc/guides/source | |
parent | 64e8f14058949b0b1967a4d1282c6fc154e890e9 (diff) | |
download | rails-b60971ad6b19a3cd72a972b459e94059d24c0848.tar.gz rails-b60971ad6b19a3cd72a972b459e94059d24c0848.tar.bz2 rails-b60971ad6b19a3cd72a972b459e94059d24c0848.zip |
Added note about update_attribute not triggering validation
Diffstat (limited to 'railties/doc/guides/source')
-rw-r--r-- | railties/doc/guides/source/activerecord_validations_callbacks.txt | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index 87f3392551..cbd914405e 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -49,6 +49,8 @@ We can see how it works by looking at the following script/console output: Saving new records means sending an SQL insert operation to the database, while saving existing records (by calling either +save+, +update_attribute+ or +update_attributes+) will result in a SQL update operation. Active Record will use this facts to perform validations upon your objects, avoiding then to be recorded to the database if their inner state is invalid in some way. You can specify validations that will be beformed every time a object is saved, just when you're creating a new record or when you're updating an existing one. +CAUTION: There are four methods that when called will trigger validation: +save+, +save!+, +update_attributes+ and +update_attributes!+. There is one method left, which is +update_attribute+. This method will update the value of an attribute without triggering any validation, so be careful when using +update_attribute+, since it can let you save your objects in an invalid state. + === The meaning of 'valid' For verifying if an object is valid, Active Record uses the +valid?+ method, which basically looks inside the object to see if it has any validation errors. These errors live in a collection that can be accessed through the +errors+ instance method. The proccess is really simple: If the +errors+ method returns an empty collection, the object is valid and can be saved. Each time a validation fails, an error message is added to the +errors+ collection. @@ -382,7 +384,7 @@ class Invoice < ActiveRecord::Base end ------------------------------------------------------------------ -If your validation rules are too complicated and you want to break it in small methods, you can implement all of them and call one of +validate+, +validate_on_create+ or +validate_on_update+ methods, passing it the symbols for the methods' names. +If your validation rules are too complicated and you want to break them in small methods, you can implement all of them and call one of +validate+, +validate_on_create+ or +validate_on_update+ methods, passing it the symbols for the methods' names. [source, ruby] ------------------------------------------------------------------ @@ -476,6 +478,7 @@ person.errors # => nil ------------------------------------------------------------------ + == Changelog http://rails.lighthouseapp.com/projects/16213/tickets/26-active-record-validations-and-callbacks |