From b60971ad6b19a3cd72a972b459e94059d24c0848 Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Tue, 18 Nov 2008 19:14:51 -0200 Subject: Added note about update_attribute not triggering validation --- .../doc/guides/html/activerecord_validations_callbacks.html | 10 +++++++++- .../doc/guides/source/activerecord_validations_callbacks.txt | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'railties/doc') diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index b6cb481eab..097ef706ca 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -362,6 +362,14 @@ http://www.gnu.org/software/src-highlite --> => false

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.
+

2.2. 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.

@@ -722,7 +730,7 @@ http://www.gnu.org/software/src-highlite --> end 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.