-
I am working on an application and I was wondering if it was possible for me to add a constraint to a schema. For instance, here is a schema: package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// User holds the schema definition for the User entity.
type User struct {
ent.Schema
}
// Fields of the User.
func (User) Fields() []ent.Field {
return []ent.Field{
field.String("first_name").NotEmpty(),
field.String("last_name").NotEmpty(),
field.Time("Birthday"),
field.String("email").Nillable().Optional(),
field.String("phone").Nillable().Optional(),
field.String("auth_id").Nillable().Optional(),
field.UUID("manager_id", uuid.UUID{}).Nillable().Optional(),
}
}
// Edges of the User.
func (User) Edges() []ent.Edge {
return []ent.Edge{
edge.To("manager", User.Type).Unique().Field("manager_id"),
}
} I want to verify that the record can never have both the |
Beta Was this translation helpful? Give feedback.
Answered by
a8m
May 5, 2023
Replies: 1 comment
-
Hey, @GV14982 👋🏻 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
a8m
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, @GV14982 👋🏻
You can accomplish this by either using Hooks (application side) and/or CHECK constraints.