Skip to content

Commit

Permalink
[Bug]: 删除台账记录时应同时删除记录附件子表记录和附件文件 #6957
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhaolin committed Jul 29, 2024
1 parent 52efe38 commit b4d3bc6
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/standard-objects/base.trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,33 @@ const afterDeleteBase = async function () {

_.each(fieldsName, function (fieldName) {
const fieldProps = fields[fieldName];
const indexOfType = fieldProps && ['file','image'].indexOf(fieldProps.type);
if( indexOfType > -1 && previousDoc[fieldName] && previousDoc[fieldName].length ){
const collection = [cfs.files,cfs.images][indexOfType];
const indexOfType = fieldProps && ['file', 'image'].indexOf(fieldProps.type);
if (indexOfType > -1 && previousDoc[fieldName] && previousDoc[fieldName].length) {
const collection = [cfs.files, cfs.images][indexOfType];
let ids = previousDoc[fieldName]
if(typeof ids === 'string'){
if (typeof ids === 'string') {
ids = [ids]
}
_.each(ids,function (id){
_.each(ids, function (id) {
collection.remove({
"_id": id
});
})
}
});
if ("cms_files" != object_name) {
// 删除附件
const cmsFilesObj = objectql.getObject('cms_files')
const cmsFiles = await cmsFilesObj.find({
filters: [
["parent/o", "=", object_name],
["parent/ids", "=", previousDoc._id]
]
})
for (const cmsFile of cmsFiles) {
await cmsFilesObj.delete(cmsFile._id)
}
}
}

module.exports = {
Expand Down

0 comments on commit b4d3bc6

Please sign in to comment.