user.go 740 B

12345678910111213141516171819202122232425262728293031323334
  1. package schema
  2. import (
  3. "github.com/facebookincubator/ent"
  4. "github.com/facebookincubator/ent/schema/edge"
  5. "github.com/facebookincubator/ent/schema/field"
  6. )
  7. // User holds the schema definition for the User entity.
  8. type User struct {
  9. ent.Schema
  10. }
  11. // Fields of the User.
  12. func (User) Fields() []ent.Field {
  13. return []ent.Field{
  14. field.Int("age").
  15. Positive(),
  16. field.String("name").
  17. Default("unknown"),
  18. }
  19. }
  20. // Edges of the User.
  21. func (User) Edges() []ent.Edge {
  22. return []ent.Edge{
  23. edge.To("cars", Car.Type),
  24. // create an inverse-edge called "groups" of type `Group`
  25. // and reference it to the "users" edge (in Group schema)
  26. // explicitly using the `Ref` method.
  27. edge.From("groups", Group.Type).
  28. Ref("users"),
  29. }
  30. }