label_relationship.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package schema
  2. import (
  3. "wechat-api/ent/schema/localmixin"
  4. "entgo.io/ent"
  5. "entgo.io/ent/dialect/entsql"
  6. "entgo.io/ent/schema"
  7. "entgo.io/ent/schema/edge"
  8. "entgo.io/ent/schema/field"
  9. "entgo.io/ent/schema/index"
  10. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  11. )
  12. type LabelRelationship struct {
  13. ent.Schema
  14. }
  15. func (LabelRelationship) Fields() []ent.Field {
  16. return []ent.Field{
  17. field.Uint64("label_id").Default(1).
  18. Annotations(entsql.WithComments(true)).
  19. Comment("标签 ID"),
  20. field.Uint64("contact_id").Default(1).
  21. Annotations(entsql.WithComments(true)).
  22. Comment("联系人 ID"),
  23. }
  24. }
  25. func (LabelRelationship) Mixin() []ent.Mixin {
  26. return []ent.Mixin{
  27. mixins.IDMixin{},
  28. mixins.StatusMixin{},
  29. localmixin.SoftDeleteMixin{},
  30. }
  31. }
  32. func (LabelRelationship) Indexes() []ent.Index {
  33. return []ent.Index{
  34. index.Fields("label_id"),
  35. index.Fields("contact_id"),
  36. }
  37. }
  38. func (LabelRelationship) Edges() []ent.Edge {
  39. return []ent.Edge{
  40. edge.From("contacts", Contact.Type).
  41. Ref("contact_relationships").
  42. Unique().
  43. Field("contact_id").
  44. Required(),
  45. edge.From("labels", Label.Type).
  46. Ref("label_relationships").
  47. Unique().
  48. Field("label_id").
  49. Required(),
  50. }
  51. }
  52. func (LabelRelationship) Annotations() []schema.Annotation {
  53. return []schema.Annotation{
  54. entsql.WithComments(true),
  55. entsql.Annotation{Table: "label_relationship"},
  56. }
  57. }