Prevent deletion of database objects if related objects exist

I am creating APIs where I don’t want objects to be deletable from a table whenever there exist relationships towards this object. What is the most efficient way of checking for this before deletion? Just do transactional Find operations for each of the tables I want to check? Or is there a simpler way?

Hello @Egil_Helland

  1. You can implement this using beforeDelete event handler which will check relations presence and throw an error if they are present.
  2. You can BULK delete using whereClause:
    DELETE <host>/<appId>/<apiKey>/data/bulk/Parent
    whereClause: objectId='<objectId>' and child is null
  • To delete a specific object: objectId='<objectId>' and child is null
  • To delete multiple objects: child is null

Regards,
Inna

Thanks @Inna_Shkolnaya, that seems like a superb solution. Any example code on using event handler for this?

Hi @Egil_Helland

in the BeforeRemove handler, you can search any objects which have relations to the removing item and if there are any just throw an exception and it interrupt the removing process

Regards,
Vlad

1 Like

Fantastic! Just what I needed. Thanks again, @vladimir-upirov !