Skip to content

Commit 35b3940

Browse files
committed
Document autosave validation behavior
1 parent ee88f41 commit 35b3940

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

activerecord/lib/active_record/associations.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,12 @@ def has_many(name, scope = nil, **options, &extension)
16611661
# When set to +true+, validates new objects added to association when saving the parent object. +false+ by default.
16621662
# If you want to ensure associated objects are revalidated on every update, use +validates_associated+.
16631663
# [+:autosave+]
1664-
# If true, always save the associated object or destroy it if marked for destruction,
1665-
# when saving the parent object. If false, never save or destroy the associated object.
1666-
# By default, only save the associated object if it's a new record.
1664+
# If +true+, always saves the associated object or destroys it if marked for destruction,
1665+
# when saving the parent object. If +false+, never save or destroy the associated object.
1666+
# By default, only saves the associated object if it's a new record. Setting this option
1667+
# to +true+ also enables validations on the associated object unless explicitly disabled
1668+
# with <tt>validate: false</tt>. This is because saving an object with invalid associated
1669+
# objects would fail, so any associated objects will go through validation checks.
16671670
#
16681671
# Note that NestedAttributes::ClassMethods#accepts_nested_attributes_for sets
16691672
# <tt>:autosave</tt> to <tt>true</tt>.

0 commit comments

Comments
 (0)