diff options
author | James Coleman <jtc331@gmail.com> | 2016-02-05 10:16:15 -0500 |
---|---|---|
committer | James Coleman <jtc331@gmail.com> | 2016-08-26 11:40:38 -0400 |
commit | a94fe2971b24d2a7827e205e7898e1b22771ed72 (patch) | |
tree | 9a6ff88242201d4fb55e29ae97146a921204bf25 /activerecord/lib | |
parent | f394f3ba763adbd073685a4a3f53b2a3ad71381a (diff) | |
download | rails-a94fe2971b24d2a7827e205e7898e1b22771ed72.tar.gz rails-a94fe2971b24d2a7827e205e7898e1b22771ed72.tar.bz2 rails-a94fe2971b24d2a7827e205e7898e1b22771ed72.zip |
Don't unnecessarily load a belongs_to when saving.
Previously, if the the association was previously loaded and then
the foreign key changed by itself, a #save call would trigger a
load of the new associated record during autosave. This is unnecessary
and the autosave code (in that case) didn't use the loaded record
anyways.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/autosave_association.rb | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 6e6620aad5..db84876b0a 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -457,7 +457,9 @@ module ActiveRecord # In addition, it will destroy the association if it was marked for destruction. def save_belongs_to_association(reflection) association = association_instance_get(reflection.name) - record = association && association.load_target + return unless association && association.loaded? && !association.stale_target? + + record = association.load_target if record && !record.destroyed? autosave = reflection.options[:autosave] |