Skip to content

Commit 42f0199

Browse files
clear changes after successful update
1 parent 1a6248e commit 42f0199

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
activerecord_batch_update (1.0.0)
4+
activerecord_batch_update (1.0.1)
55
activerecord (>= 7.0, < 8.1)
66
activesupport (>= 7.0, < 8.1)
77

activerecord_batch_update.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |s|
44
s.name = 'activerecord_batch_update'
5-
s.version = '1.0.0'
5+
s.version = '1.0.1'
66
s.summary = 'Update multiple records with different values in a small number of queries'
77
s.description = ''
88
s.authors = ['Quentin de Metz']

lib/activerecord_batch_update.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def batch_update(entries, columns:, batch_size: 100, validate: true)
3535
end
3636

3737
connection.clear_query_cache if connection.query_cache_enabled
38+
entries.each(&:changes_applied)
3839

3940
updated_count
4041
end

spec/activerecord_batch_update_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@
180180
.and(change { cat2.reload.birthday })
181181
end
182182

183+
it 'clears the changes after the update' do
184+
cat1.name = 'Nala'
185+
Cat.batch_update([cat1], columns: :all)
186+
187+
expect(cat1.changes_to_save).to be_empty
188+
end
189+
183190
context 'when some fields are encrypted' do
184191
let!(:cat1) { Cat.create!(name: 'Felix', birthday: Date.new(2010, 1, 1)) }
185192

0 commit comments

Comments
 (0)