;(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: "",
        })
    })
})()
