Soft deleting #41
Labels
discussion
Something that should be discussed
documentation
Improvements or additions to documentation
enhancement
New feature or request
Projects
What is a soft delete?
A soft delete marks a record as no longer active or valid without actually deleting it from the database. Soft deletes can improve performance, and can allow “deleted” data to be recovered. [*]
Motivations
Developers should be able to add soft-delete features to the models.
Implementation
To add a soft-delete feature to a model, developers must add the following code to the model file;
deletedAtColumn
should returnNULL
from the baseModel
. If developers add a database field name, it means that we have a soft-deleting feature for this model. Developers must create atimestamps
data field on the database via migrations.Soft-Deleting Record
The
DELETE
handler must work as the soft-deleting if there is soft-deleting support. Otherwise, it must work like a normal delete.On the other hand, developers should be able to add
FORCE_DELETE
handler to models like the following example to support the force delete feature;Queries
Clients should not be able to see the soft-deleted records in queries (
PAGINATE
,SHOW
). Also, clients should not be able to manipulate the soft-deleted records (UPDATE
,PATCH
).In addition, the
with
keyword that fetches the related data should work with the soft-deleting feature perfectly.Also, related data fetch must work perfectly with soft deleting. For example; the
/api/users/1/posts
request should check if theuser 1
is soft-deleted or not. (#132)Force Delete Handler
This would be a new handler for force deleting.
Listing deleted values
Clients should be able to fetch soft-deleted records from a database. To do that, they must use the following command;
Hooks & Events
The following hooks and events should be supported for the force-delete handler;
Todo List
deletedAtColumn
column to the baseModel
DELETE
handler works.FORCE_DELETE
handler.with
operator works.trashed
parameter to the queries.PUT
,PATCH
/api/users/1/posts
)Acceptance Criteria
/api/users/1/customers
=> Customer)/api/users?with=customers
=> Customer)/api/customers/1/phones
=> Customer)/api/phones?with=customer
=> Customer)trashed
record by the query parameters (PAGINATE, SHOW, ALL)Documentation Change
The text was updated successfully, but these errors were encountered: