DeletePolicy
Type Alias: DeletePolicy
DeletePolicy =
"CASCADE"|"RESTRICT"|"SET_NULL"|"NONE"
Defined in: packages/models/src/relations.ts:545
What happens to the dependents of a model when it is deleted
Declared on the relation with the @OnDelete <POLICY> JSDoc tag (@CascadeDelete is a synonym of
@OnDelete CASCADE), defaulted from the relation kind otherwise:
| Policy | Effect when the target of the relation is deleted |
|---|---|
CASCADE | Delete every dependent, through the repository so its own events fire and it cascades in turn |
RESTRICT | Refuse the delete with a 409 Conflict while a dependent exists |
SET_NULL | Remove the attribute of each dependent (a single link) or the item (a link array) |
NONE | Do nothing |
| Relation | Default |
|---|---|
ModelParent / BelongTo | CASCADE (SET_NULL is refused: a parent is mandatory) |
ModelLink / RelateTo / ManyToOne / OneToOne | NONE |
ModelLinksSimpleArray / ModelLinksArray / ManyToMany | NONE |
Contains (declared on the owner) | CASCADE: deleting the owner deletes the listed models |
The RelationIntegrity service of @webda/core applies the policies, on the repository Delete / Deleted
events: Repository.deleteMany emits none, so it never cascades.
class Comment extends UuidModel {
post: BelongTo<Post>; // CASCADE
/** @OnDelete RESTRICT */
author: BelongTo<User>; // a user with comments cannot be deleted
/** @OnDelete SET_NULL */
reviewer: RelateTo<User>;
}