aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2018-12-03 17:24:29 -0500
committerGannon McGibbon <gannon.mcgibbon@gmail.com>2018-12-04 00:16:42 -0500
commit67bca35a64e0fde994270b242f0b1c59d8e56b0b (patch)
tree6eb2dd1ff18c3380f633446394f9b78c275ec680 /activerecord/lib/active_record/associations
parent6ca6478a67ecdff58c29d10cd408b7259ed89e2b (diff)
downloadrails-67bca35a64e0fde994270b242f0b1c59d8e56b0b.tar.gz
rails-67bca35a64e0fde994270b242f0b1c59d8e56b0b.tar.bz2
rails-67bca35a64e0fde994270b242f0b1c59d8e56b0b.zip
Reset scope after collection delete
Reset scope after delete on collection association to clear stale offsets of removed records.
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r--activerecord/lib/active_record/associations/collection_proxy.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb
index 811fbfd927..4fbbc713e4 100644
--- a/activerecord/lib/active_record/associations/collection_proxy.rb
+++ b/activerecord/lib/active_record/associations/collection_proxy.rb
@@ -500,7 +500,7 @@ module ActiveRecord
# Pet.find(1, 2, 3)
# # => ActiveRecord::RecordNotFound: Couldn't find all Pets with 'id': (1, 2, 3)
def delete_all(dependent = nil)
- @association.delete_all(dependent)
+ @association.delete_all(dependent).tap { reset_scope }
end
# Deletes the records of the collection directly from the database
@@ -527,7 +527,7 @@ module ActiveRecord
#
# Pet.find(1) # => Couldn't find Pet with id=1
def destroy_all
- @association.destroy_all
+ @association.destroy_all.tap { reset_scope }
end
# Deletes the +records+ supplied from the collection according to the strategy
@@ -646,7 +646,7 @@ module ActiveRecord
# # #<Pet id: 3, name: "Choo-Choo", person_id: 1>
# # ]
def delete(*records)
- @association.delete(*records)
+ @association.delete(*records).tap { reset_scope }
end
# Destroys the +records+ supplied and removes them from the collection.
@@ -718,7 +718,7 @@ module ActiveRecord
#
# Pet.find(4, 5, 6) # => ActiveRecord::RecordNotFound: Couldn't find all Pets with 'id': (4, 5, 6)
def destroy(*records)
- @association.destroy(*records)
+ @association.destroy(*records).tap { reset_scope }
end
##