car.go 767 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. // Car holds the schema definition for the Car entity.
  8. type Car struct {
  9. ent.Schema
  10. }
  11. // Fields of the Car.
  12. func (Car) Fields() []ent.Field {
  13. return []ent.Field{
  14. field.String("model"),
  15. field.Time("registered_at"),
  16. }
  17. }
  18. // Edges of the Car.
  19. func (Car) Edges() []ent.Edge {
  20. return []ent.Edge{
  21. // create an inverse-edge called "owner" of type `User`
  22. // and reference it to the "cars" edge (in User schema)
  23. // explicitly using the `Ref` method.
  24. edge.From("owner", User.Type).
  25. Ref("cars").
  26. // setting the edge to unique, ensure
  27. // that a car can have only one owner.
  28. Unique(),
  29. }
  30. }