packages start...
This commit is contained in:
18
api/hooks/medialib/delete_return.js
Normal file
18
api/hooks/medialib/delete_return.js
Normal file
@@ -0,0 +1,18 @@
|
||||
;(function () {
|
||||
const request = context.request()
|
||||
//get id of deleted image entry (delete request URL is : .../api/_/demo/medialib/id)
|
||||
const id = request.param("id")
|
||||
|
||||
//find all entrys where there is an image field with the id of this deleted one (image is an foreignKey widget, so stores the id as a string internally)
|
||||
const referencingElements = context.db.find("democol", {
|
||||
filter: {
|
||||
image: id,
|
||||
},
|
||||
})
|
||||
referencingElements.forEach((e) => {
|
||||
//update all those entries to remove the image id from them, since its deleted...
|
||||
context.db.update("democol", e.id, {
|
||||
image: "",
|
||||
})
|
||||
})
|
||||
})()
|
||||
Reference in New Issue
Block a user