group.go 541 B

123456789101112131415161718192021222324252627282930
  1. package schema
  2. import (
  3. "regexp"
  4. "entgo.io/ent"
  5. "entgo.io/ent/schema/edge"
  6. "entgo.io/ent/schema/field"
  7. )
  8. // Group holds the schema definition for the Group entity.
  9. type Group struct {
  10. ent.Schema
  11. }
  12. // Fields of the Group.
  13. func (Group) Fields() []ent.Field {
  14. return []ent.Field{
  15. field.String("name").
  16. // Regexp validation for group name
  17. Match(regexp.MustCompile("[a-zA-Z_]+$")),
  18. }
  19. }
  20. // Edges of the Group.
  21. func (Group) Edges() []ent.Edge {
  22. return []ent.Edge{
  23. edge.To("users", User.Type), // cf User.Edges: "groups"
  24. }
  25. }