3

Deleting an item from a collection, which has a status field, through the UI or API results in the item being soft deleted. However, in this one particular instance, we want to remove it from the database entirely.

If not possible, can it safely be done through the database by just deleting it from the table carrying the name of the collection? Any side-effects when doing it this way?

Davey Chu
  • 2,174
  • 2
  • 14
  • 24
  • By item do you mean a record or a collection? For the second question, deleting from the Database should be totally find for Directus. I'd suggest also removing the records related to that item in the system tables (directus_collections/fields) – Daniel Stoyanoff Aug 31 '21 at 12:40
  • A record. So basically this https://docs.directus.io/reference/api/items/#delete-an-item, but actually removing the record instead of soft deleting by setting the "deleted" field to true. – Davey Chu Sep 09 '21 at 08:24
  • Directus will not do a soft delete. You are the one defining your database tables in your custom collections. Directus will not add there any system field, as their concept is not touching your main schema. So not sure what your setup is to cause soft deletes – Daniel Stoyanoff Sep 09 '21 at 08:34
  • Apparently soft-delete behavior is added by the status field (https://v8.docs.directus.io/guides/status.html#soft-delete). Edited the question. – Davey Chu Sep 19 '21 at 19:36
  • Ah, sorry. I thought it's for V9, my bad. – Daniel Stoyanoff Sep 20 '21 at 13:39

1 Answers1

1

Found the answer on this page https://v8.docs.directus.io/guides/status.html#soft-delete:

When deleting an item, the API does the following:

Check if the collection has a status field
Check if the delta data has the status field (meaning the status was changed)
Check if the new status value (from delta data) has soft_delete = true
If yes, it sets the action to SOFT_DELETE
If no, it hard deletes the item (permanently removed from the database)
Davey Chu
  • 2,174
  • 2
  • 14
  • 24