aboutsummaryrefslogtreecommitdiffstats
path: root/railties/doc/guides/source
diff options
context:
space:
mode:
authorCassioMarques <cassiommc@gmail.com>2008-11-07 21:17:57 -0200
committerCassioMarques <cassiommc@gmail.com>2008-11-07 21:17:57 -0200
commit879eba22f220c8e7c779786eb68f31631f59a53c (patch)
tree3b1f4c0e42a97bfe5d66fa87bfc14b562422a964 /railties/doc/guides/source
parent0c3752390cf9b4f64169e9eb5ad860aec691edeb (diff)
downloadrails-879eba22f220c8e7c779786eb68f31631f59a53c.tar.gz
rails-879eba22f220c8e7c779786eb68f31631f59a53c.tar.bz2
rails-879eba22f220c8e7c779786eb68f31631f59a53c.zip
added doc for validates_associated
Diffstat (limited to 'railties/doc/guides/source')
-rw-r--r--railties/doc/guides/source/activerecord_validations_callbacks.txt16
1 files changed, 16 insertions, 0 deletions
diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt
index d0d9d265aa..eaf7b428ba 100644
--- a/railties/doc/guides/source/activerecord_validations_callbacks.txt
+++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt
@@ -84,6 +84,22 @@ end
=== The +validates_associated+ helper
+You should use this helper when your model has associations with other models and they also need to be validated. When you try to save your object, +valid?+ will be called upon each one of the associated objects.
+
+[source, ruby]
+------------------------------------------------------------------
+class Library < ActiveRecord::Base
+ has_many :books
+ validates_associated :books
+end
+------------------------------------------------------------------
+
+This validation will work with all the association types.
+
+CAUTION: Pay attention not to use +validates_associated+ on both ends of your associations, because this will lead to several recursive calls and blow up the method calls' stack.
+
+The default error message for +validates_associated+ is "_is invalid_". Note that the errors for each failed validation in the associated objects will be set there and not in this model.
+
=== The +validates_confirmation_of+ helper
=== The +validates_each+ helper