contact_field.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package schema
  2. import (
  3. "entgo.io/ent/schema/edge"
  4. "wechat-api/ent/schema/localmixin"
  5. "entgo.io/ent"
  6. "entgo.io/ent/dialect/entsql"
  7. "entgo.io/ent/schema"
  8. "entgo.io/ent/schema/field"
  9. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  10. )
  11. type ContactField struct {
  12. ent.Schema
  13. }
  14. func (ContactField) Fields() []ent.Field {
  15. return []ent.Field{
  16. field.Uint64("contact_id").Default(1).
  17. Comment("联系人 ID").
  18. Annotations(entsql.WithComments(true)),
  19. field.String("form_id").
  20. Annotations(entsql.WithComments(true)).
  21. Comment("表单 id"),
  22. field.JSON("value", []string{}).
  23. Annotations(entsql.WithComments(true)).
  24. Comment("表单值"),
  25. }
  26. }
  27. func (ContactField) Mixin() []ent.Mixin {
  28. return []ent.Mixin{
  29. mixins.IDMixin{},
  30. mixins.StatusMixin{},
  31. localmixin.SoftDeleteMixin{},
  32. }
  33. }
  34. func (ContactField) Indexes() []ent.Index {
  35. return []ent.Index{}
  36. }
  37. func (ContactField) Edges() []ent.Edge {
  38. return []ent.Edge{
  39. edge.From("field_contact", Contact.Type).
  40. Ref("contact_fields").
  41. Unique().
  42. Field("contact_id").
  43. Required(),
  44. }
  45. }
  46. func (ContactField) Annotations() []schema.Annotation {
  47. return []schema.Annotation{
  48. entsql.WithComments(true),
  49. entsql.Annotation{Table: "contact_field"},
  50. }
  51. }