讨论创建接口兼容附件uuid

This commit is contained in:
xxq250 2026-07-23 10:00:25 +08:00
parent f3f3245277
commit daaf2b30c5
1 changed files with 13 additions and 1 deletions

View File

@ -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