group.go 578 B

123456789101112131415161718192021222324252627282930
  1. package schema
  2. import (
  3. "regexp"
  4. "github.com/facebookincubator/ent"
  5. "github.com/facebookincubator/ent/schema/edge"
  6. "github.com/facebookincubator/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 the 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),
  24. }
  25. }