Annotations

    Foreign Keys Configuration

    1. package schema
    2. import (
    3. "entgo.io/ent"
    4. "entgo.io/ent/dialect/entsql"
    5. "entgo.io/ent/schema/edge"
    6. "entgo.io/ent/schema/field"
    7. )
    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.String("name").
    15. Default("Unknown"),
    16. // Edges of the User.
    17. func (User) Edges() []ent.Edge {
    18. return []ent.Edge{
    19. edge.To("posts", Post.Type).
    20. Annotations(entsql.Annotation{
    21. OnDelete: entsql.Cascade,
    22. }),
    23. }