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 --- .../guides/source/activerecord_validations_callbacks.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'railties/doc/guides/source') 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