Skip to content

Commit

Permalink
Merge pull request #50856 from Dmoment/docs-autosave-validations
Browse files Browse the repository at this point in the history
Document autosave validation behavior for ActiveRecord associations [ci skip]
  • Loading branch information
rafaelfranca authored Apr 19, 2024
2 parents 73452ef + 83033a4 commit 5e4f2d3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>validate: false</tt>. 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
# <tt>:autosave</tt> to <tt>true</tt>.
Expand Down

0 comments on commit 5e4f2d3

Please sign in to comment.