Files
tinyquiz/pkg/model/ent/schema/choice.go
Vojtěch Káně 41ae2283b1 Update ent
The package changed its import path so we had to reflect
2021-02-18 14:51:45 +01:00

41 lines
666 B
Go

package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
type Choice struct {
ent.Schema
}
func (Choice) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.Nil).Immutable(),
field.Text("title").MinLen(1).MaxLen(256),
field.Bool("correct"),
}
}
func (Choice) Indexes() []ent.Index {
return []ent.Index{}
}
func (Choice) Edges() []ent.Edge {
return []ent.Edge{
edge.From("question", Question.Type).
Ref("choices").
Unique().
Required(),
edge.To("answers", Answer.Type),
}
}
func (Choice) Config() ent.Config {
return ent.Config{
Table: "options",
}
}