From 879eba22f220c8e7c779786eb68f31631f59a53c Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Fri, 7 Nov 2008 21:17:57 -0200 Subject: added doc for validates_associated --- .../html/activerecord_validations_callbacks.html | 21 +++++++++++++++++++++ .../source/activerecord_validations_callbacks.txt | 16 ++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index a645f175fd..7125b7252f 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -370,6 +370,27 @@ http://www.gnu.org/software/src-highlite --> end

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

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

3.3. The validates_confirmation_of helper

3.4. The validates_each helper

3.5. The validates_exclusion_of helper

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 -- cgit v1.2.3