From 131ed24f5ef41f5470e83fb66cfff61f635bf24d Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 30 Jun 2017 02:29:52 +0900 Subject: Should be clear `@association_ids` when joined newly associated record Fixes #29627. --- .../active_record/associations/collection_association.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations/collection_association.rb') diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index bbf3dbb75e..a49fb155ee 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -66,6 +66,7 @@ module ActiveRecord def reset super @target = [] + @association_ids = nil end def find(*args) @@ -355,7 +356,10 @@ module ActiveRecord transaction do add_to_target(build_record(attributes)) do |record| yield(record) if block_given? - insert_record(record, true, raise) { @_was_loaded = loaded? } + insert_record(record, true, raise) { + @_was_loaded = loaded? + @association_ids = nil + } end end end @@ -428,7 +432,12 @@ module ActiveRecord records.each do |record| raise_on_type_mismatch!(record) add_to_target(record) do - result &&= insert_record(record, true, raise) { @_was_loaded = loaded? } unless owner.new_record? + unless owner.new_record? + result &&= insert_record(record, true, raise) { + @_was_loaded = loaded? + @association_ids = nil + } + end end end -- cgit v1.2.3 From cfade1ec7ee7b5b51f3c1578e3474f9c156f2971 Mon Sep 17 00:00:00 2001 From: Kir Shatrov Date: Thu, 22 Jun 2017 22:59:18 -0400 Subject: Enforce frozen string in Rubocop --- activerecord/lib/active_record/associations/collection_association.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activerecord/lib/active_record/associations/collection_association.rb') diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index bbf3dbb75e..f73b0b90cf 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module ActiveRecord module Associations # = Active Record Association Collection -- cgit v1.2.3 From 87b3e226d65ac1ed371620bfdcd2f950c87cfece Mon Sep 17 00:00:00 2001 From: Matthew Draper Date: Sun, 2 Jul 2017 02:15:17 +0930 Subject: Revert "Merge pull request #29540 from kirs/rubocop-frozen-string" This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa. --- activerecord/lib/active_record/associations/collection_association.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activerecord/lib/active_record/associations/collection_association.rb') diff --git a/activerecord/lib/active_record/associations/collection_association.rb b/activerecord/lib/active_record/associations/collection_association.rb index 8bed7121a8..a49fb155ee 100644 --- a/activerecord/lib/active_record/associations/collection_association.rb +++ b/activerecord/lib/active_record/associations/collection_association.rb @@ -1,4 +1,3 @@ -# frozen_string_literal: true module ActiveRecord module Associations # = Active Record Association Collection -- cgit v1.2.3