aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2017-07-01 22:33:27 +0930
committerGitHub <noreply@github.com>2017-07-01 22:33:27 +0930
commite469e9dfac933d66ae4f7aae152aeb5c4be80bc7 (patch)
tree052452cd7f299923c18ef8163b054a08dc6c71ab /activerecord/lib/active_record/associations
parente1784c2e008a1150a1ee8b18d21ad3795e985e66 (diff)
parent131ed24f5ef41f5470e83fb66cfff61f635bf24d (diff)
downloadrails-e469e9dfac933d66ae4f7aae152aeb5c4be80bc7.tar.gz
rails-e469e9dfac933d66ae4f7aae152aeb5c4be80bc7.tar.bz2
rails-e469e9dfac933d66ae4f7aae152aeb5c4be80bc7.zip
Merge pull request #29631 from kamipo/should_be_clear_association_ids
Should be clear `@association_ids` when joined newly associated record
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/collection_association.rb13
1 files changed, 11 insertions, 2 deletions
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