forked from Gitlink/forgeplus
讨论创建接口兼容附件uuid
This commit is contained in:
parent
f3f3245277
commit
daaf2b30c5
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue