Permalink
Browse files

Remove API links and add TODOs #26

  • Loading branch information...
1 parent ed1f674 commit d39290cf0e582993bdfcd48f92544da174788c05 @lifo lifo committed Feb 4, 2009
Showing with 22 additions and 16 deletions.
  1. +22 −16 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.

0 comments on commit d39290c

Please sign in to comment.