From d39290cf0e582993bdfcd48f92544da174788c05 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Wed, 4 Feb 2009 14:38:45 +0000 Subject: Remove API links and add TODOs #26 --- .../activerecord_validations_callbacks.textile | 38 +++++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/source/activerecord_validations_callbacks.textile b/railties/guides/source/activerecord_validations_callbacks.textile index 75c4cf69d5..c4effb374e 100644 --- a/railties/guides/source/activerecord_validations_callbacks.textile +++ b/railties/guides/source/activerecord_validations_callbacks.textile @@ -55,34 +55,40 @@ CAUTION: There are many ways to change the state of an object in the database. S The following methods trigger validations and generally save the object to the database: -* "create":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002214 (creates an object, but does not save to the database) -* "create!":http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M002116 -* "save":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002274 -* "save!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002275 -* "update":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002215 -* "update_attributes":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002281 -* "update_attributes!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002282 +* +create+ +* +create!+ +* +save+ +* +save!+ +* +update+ +* +update_attributes+ +* +update_attributes!+ The following methods _do not_ trigger validations, but _do_ change the state of the object in the database. They should be used with caution: -* "decrement!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002286 -* "decrement_counter":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002224 -* "increment!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002284 -* "increment_counter":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002223 -* "toggle":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002287 -* "toggle!":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002288 -* "update_all":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002218 -* "update_attribute":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002280 -* "update_counters":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002222 +* +decrement!+ +* +decrement_counter+ +* +increment!+ +* +increment_counter+ +* +toggle+ +* +toggle!+ +* +update_all+ +* +update_attribute+ +* +update_counters+ Note that +save+ has the ability to bypass validations. This technique should be used with caution: * "save(false)":http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M002274 +h4. Skipping Validations + +TODO: Probably move the list above and mention save(false). Also mention that save(false) doesn't only skip the validations, but a lots of other callbacks too. + h4. Object#valid? To verify whether 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 process 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. +h4. Object#invalid? + h3. Declarative Validation Helpers Active Record offers many pre-defined validation helpers that you can use directly inside your class definitions. These helpers create validation rules that are commonly used. Every time a validation fails, an error message is added to the object's +errors+ collection, and this message is associated with the field being validated. -- cgit v1.2.3