Grist "built in" child record protection system

In this thread, I suggested how to block deleting a record if it has child records, thus protecting it from leaving orphaned child records. It would use a status column that counts child records and if status is 0, then based on User Permissions, the record is free to delete. If status is 1, it’s blocked.

While the system is not DIFFICULT to implement, I never implemented it even though I suggested how. Simply because having to set this kind of rules manually, creating a maze in the rules table, becomes way too complicated. Grist could do it automatically, behind the curtains, with some CHECK button when setting child records.

I do it exactly as you propose, however I believe it would be much more robust and fool-proof if the mechanism was implemented through foreign keys at the SQLite level

1 Like

I do it this way as well, it’s pretty easy to setup with a “count” column and Access Rules.

I agree, however, that Grist tables could/should have a flag like “prevent deletions if columns are referenced by other tables”, and I would default it to “Yes”.

I 1000% agree with Piergorgio.

SQLite has an option PRAGMA foreign_keys=ON which can be set to enable this.

Question for support: Can this option be set on self-hosted sites? I haven’t been able to find any documentation about it.

This is my current solution, an as Rogerio says, it can “create a maze”.

Formula for DeleteLock in People table:
image