aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/lib/active_storage/attached
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-07-16 15:57:43 -0400
committerGeorge Claghorn <george@basecamp.com>2018-07-16 15:57:43 -0400
commit36ec5428bfe78831e4c5c001bd8e7ce45c238b33 (patch)
tree4fcdf44f8dd90aac4d926da99be2f5a0b3e5ceba /activestorage/lib/active_storage/attached
parent1d13de4e39aa8045d1829ebbec5f7a8a192ed4b2 (diff)
downloadrails-36ec5428bfe78831e4c5c001bd8e7ce45c238b33.tar.gz
rails-36ec5428bfe78831e4c5c001bd8e7ce45c238b33.tar.bz2
rails-36ec5428bfe78831e4c5c001bd8e7ce45c238b33.zip
Fix that successive ActiveStorage::Attached::Many#attach calls would overwrite previous attachments
Diffstat (limited to 'activestorage/lib/active_storage/attached')
-rw-r--r--activestorage/lib/active_storage/attached/changes/create_many.rb12
1 files changed, 11 insertions, 1 deletions
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