diff options
author | Will Jessop <will@willj.net> | 2019-07-13 20:52:32 +0100 |
---|---|---|
committer | Will Jessop <will@willj.net> | 2019-07-15 18:21:20 +0100 |
commit | 6ea80b6103de9ef76dca9d51149dd94bec846642 (patch) | |
tree | a95a56cfd09163e4c79ac95af69d0afb467c2126 /activerecord/lib | |
parent | 88b91299f3fc5b912e10323ed0ad18c87c7584e5 (diff) | |
download | rails-6ea80b6103de9ef76dca9d51149dd94bec846642.tar.gz rails-6ea80b6103de9ef76dca9d51149dd94bec846642.tar.bz2 rails-6ea80b6103de9ef76dca9d51149dd94bec846642.zip |
Don't validate non dirty association targets
Fixes #36581.
This fixes an issue where validations would return differently when a previously saved invalid association was loaded between calls:
assert_equal true, squeak.valid?
assert_equal true, squeak.mouse.present?
assert_equal true, squeak.valid?
Here the second assert would return
Expected: true
Actual: false
Limiting validations to associations that would be normally saved (using autosave: true) due to changes means that loading invalid associated relations will not change the return value of the parent relations's `valid?` method.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 94d8134b55..734ebb45ae 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -302,7 +302,7 @@ module ActiveRecord def validate_single_association(reflection) association = association_instance_get(reflection.name) record = association && association.reader - association_valid?(reflection, record) if record + association_valid?(reflection, record) if record && record.changed_for_autosave? end # Validate the associated records if <tt>:validate</tt> or |