From 35b3940432c8c346bcd5e464b0434e5430734deb Mon Sep 17 00:00:00 2001 From: Deepak Chauhan Date: Wed, 24 Jan 2024 00:53:01 +0530 Subject: [PATCH] Document autosave validation behavior --- activerecord/lib/active_record/associations.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index c977929957..eace7d1c3b 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1661,9 +1661,12 @@ def has_many(name, scope = nil, **options, &extension) # When set to +true+, validates new objects added to association when saving the parent object. +false+ by default. # If you want to ensure associated objects are revalidated on every update, use +validates_associated+. # [+:autosave+] - # If true, always save the associated object or destroy it if marked for destruction, - # when saving the parent object. If false, never save or destroy the associated object. - # By default, only save the associated object if it's a new record. + # If +true+, always saves the associated object or destroys it if marked for destruction, + # when saving the parent object. If +false+, never save or destroy the associated object. + # By default, only saves the associated object if it's a new record. Setting this option + # to +true+ also enables validations on the associated object unless explicitly disabled + # with validate: false. This is because saving an object with invalid associated + # objects would fail, so any associated objects will go through validation checks. # # Note that NestedAttributes::ClassMethods#accepts_nested_attributes_for sets # :autosave to true.