PostgreSQL on delete cascade not working - Strapi changes child's foreign key before deleting parent entry

System Information
  • Strapi Version: 3.6.8
  • Operating System: MacOS Big Sur 11.4
  • Database: PostgreSQL
  • Node Version: v14.15.0
  • NPM Version: 6.14.8
  • Yarn Version:

I have a Collection Type with a 1 to 1 relation and the corresponding underlying PostgreSQL schema. I would like to have a foreign key constraint with a cascade on deletion, meaning when I delete the parent entry, I want to delete the child entry from the db as well.

I know this feature is currently on the roadmap: Cascade delete - Roadmap | Product Roadmap

However, I assumed it should be possible to just add this constraint separately in my db schema. After adding this constraint, I found that the constraint works when deleting an entry in my db directly (e.g. with DBeaver) but when deleting the entry over strapi, the constraint doesn’t seem to affect the child entries.

After debugging, I found the reason for this. When deleting an entry, strapi first updates the child collection types by setting the foreign key to null and then deleting the entry. Thus, the constraint is not triggered.

I was wondering if there is any way of customizing this behavior so my constraint can work or is the only possible way of achieving this with custom controllers/services, which would be much more work in my case?