Add OnDelete annotation to each edge
This commit is contained in:
@@ -2,6 +2,7 @@ package schema
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -29,6 +30,9 @@ func (Choice) Edges() []ent.Edge {
|
|||||||
Ref("choices").
|
Ref("choices").
|
||||||
Unique().
|
Unique().
|
||||||
Required(),
|
Required(),
|
||||||
edge.To("answers", Answer.Type),
|
edge.To("answers", Answer.Type).
|
||||||
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Restrict,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package schema
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -23,7 +24,13 @@ func (Game) Fields() []ent.Field {
|
|||||||
|
|
||||||
func (Game) Edges() []ent.Edge {
|
func (Game) Edges() []ent.Edge {
|
||||||
return []ent.Edge{
|
return []ent.Edge{
|
||||||
edge.To("sessions", Session.Type),
|
edge.To("sessions", Session.Type).
|
||||||
edge.To("questions", Question.Type),
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Restrict,
|
||||||
|
}),
|
||||||
|
edge.To("questions", Question.Type).
|
||||||
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Cascade,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package schema
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"entgo.io/ent/schema/index"
|
"entgo.io/ent/schema/index"
|
||||||
@@ -34,6 +35,9 @@ func (Player) Edges() []ent.Edge {
|
|||||||
Ref("players").
|
Ref("players").
|
||||||
Unique().
|
Unique().
|
||||||
Required(),
|
Required(),
|
||||||
edge.To("answers", Answer.Type),
|
edge.To("answers", Answer.Type).
|
||||||
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Cascade,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package schema
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"entgo.io/ent/schema/index"
|
"entgo.io/ent/schema/index"
|
||||||
@@ -33,7 +34,13 @@ func (Question) Edges() []ent.Edge {
|
|||||||
Ref("questions").
|
Ref("questions").
|
||||||
Unique().
|
Unique().
|
||||||
Required(),
|
Required(),
|
||||||
edge.To("choices", Choice.Type),
|
edge.To("choices", Choice.Type).
|
||||||
edge.To("asked", AskedQuestion.Type),
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Cascade,
|
||||||
|
}),
|
||||||
|
edge.To("asked", AskedQuestion.Type).
|
||||||
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Restrict,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package schema
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"entgo.io/ent"
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/entsql"
|
||||||
"entgo.io/ent/schema/edge"
|
"entgo.io/ent/schema/edge"
|
||||||
"entgo.io/ent/schema/field"
|
"entgo.io/ent/schema/field"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@@ -30,7 +31,13 @@ func (Session) Edges() []ent.Edge {
|
|||||||
Ref("sessions").
|
Ref("sessions").
|
||||||
Unique().
|
Unique().
|
||||||
Required(),
|
Required(),
|
||||||
edge.To("players", Player.Type),
|
edge.To("players", Player.Type).
|
||||||
edge.To("askedQuestions", AskedQuestion.Type),
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Cascade,
|
||||||
|
}),
|
||||||
|
edge.To("askedQuestions", AskedQuestion.Type).
|
||||||
|
Annotations(entsql.Annotation{
|
||||||
|
OnDelete: entsql.Cascade,
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user