From baaa22d018c1f4da2843fb2ba2e371f9d7470a44 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Sun, 9 Apr 2023 23:36:35 +0700 Subject: [PATCH] entsql: added OnDelete annotation (#3459) Signed-off-by: Giau. Tran Minh --- dialect/entsql/annotation.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/dialect/entsql/annotation.go b/dialect/entsql/annotation.go index f0ff39625..c03cb0dc9 100644 --- a/dialect/entsql/annotation.go +++ b/dialect/entsql/annotation.go @@ -229,6 +229,23 @@ func WithComments(b bool) *Annotation { } } +// OnDelete specifies a custom referential action for DELETE operations on parent +// table that has matching rows in the child table. +// +// For example, in order to delete rows from the parent table and automatically delete +// their matching rows in the child table, pass the following annotation: +// +// func (T) Annotations() []schema.Annotation { +// return []schema.Annotation{ +// entsql.OnDelete(entsql.Cascade), +// } +// } +func OnDelete(opt ReferenceOption) *Annotation { + return &Annotation{ + OnDelete: opt, + } +} + // Merge implements the schema.Merger interface. func (a Annotation) Merge(other schema.Annotation) schema.Annotation { var ant Annotation