From 36ec5428bfe78831e4c5c001bd8e7ce45c238b33 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Mon, 16 Jul 2018 15:57:43 -0400 Subject: Fix that successive ActiveStorage::Attached::Many#attach calls would overwrite previous attachments --- .../lib/active_storage/attached/changes/create_many.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'activestorage/lib') diff --git a/activestorage/lib/active_storage/attached/changes/create_many.rb b/activestorage/lib/active_storage/attached/changes/create_many.rb index af19328a61..a7a8553e0f 100644 --- a/activestorage/lib/active_storage/attached/changes/create_many.rb +++ b/activestorage/lib/active_storage/attached/changes/create_many.rb @@ -21,7 +21,8 @@ module ActiveStorage end def save - record.public_send("#{name}_attachments=", attachments) + assign_associated_attachments + reset_associated_blobs end private @@ -32,5 +33,14 @@ module ActiveStorage def build_subchange_from(attachable) ActiveStorage::Attached::Changes::CreateOneOfMany.new(name, record, attachable) end + + + def assign_associated_attachments + record.public_send("#{name}_attachments=", attachments) + end + + def reset_associated_blobs + record.public_send("#{name}_blobs").reset + end end end -- cgit v1.2.3