From daaf2b30c53ea9a66e0054243090408729d16bda Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 23 Jul 2026 10:00:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E5=88=9B=E5=BB=BA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=85=BC=E5=AE=B9=E9=99=84=E4=BB=B6uuid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/memo.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/memo.rb b/app/models/memo.rb index aa0af8a02..30fb80490 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -188,7 +188,19 @@ class Memo < ApplicationRecord end def update_attachments(attachment_ids) - Attachment.where(id: attachment_ids).update_all(container_id: id, container_type: "Memo") + if attachment_ids.present? + attachment_ids = attachment_ids -[nil] if attachment_ids.is_a? Array + old_attachment_uuids = Attachment.where(container_id: id, container_type: "Memo").pluck(:uuid) + if old_attachment_uuids.present? + del_attachment_uuids = old_attachment_uuids - attachment_ids + Attachment.where(uuid: del_attachment_uuids).update_all(container_id: nil, container_type: nil) + end + if attachment_ids.present? + Attachment.where(uuid: attachment_ids).update_all(container_id: id, container_type: "Memo") + end + else + Attachment.where(container_id: id, container_type: "Memo").update_all(container_id: nil, container_type: nil) + end end private