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/test | |
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/test')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb index 3f42cb9b9d..2418346d1b 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -626,6 +626,12 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_queries(0) { tagging.super_tag } end + def test_dont_find_target_when_saving_foreign_key_after_stale_association_loaded + client = Client.create!(name: "Test client", firm_with_basic_id: Firm.find(1)) + client.firm_id = Firm.create!(name: "Test firm").id + assert_queries(1) { client.save! } + end + def test_field_name_same_as_foreign_key computer = Computer.find(1) assert_not_nil computer.developer, ":foreign key == attribute didn't lock up" # ' |