label_relationship.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. field.Uint64("organization_id").Optional().Default(1).
  24. Comment("机构 ID").
  25. Annotations(entsql.WithComments(true)),
  26. }
  27. }
  28. func (LabelRelationship) Mixin() []ent.Mixin {
  29. return []ent.Mixin{
  30. mixins.IDMixin{},
  31. mixins.StatusMixin{},
  32. localmixin.SoftDeleteMixin{},
  33. }
  34. }
  35. func (LabelRelationship) Indexes() []ent.Index {
  36. return []ent.Index{
  37. index.Fields("label_id"),
  38. index.Fields("contact_id"),
  39. }
  40. }
  41. func (LabelRelationship) Edges() []ent.Edge {
  42. return []ent.Edge{
  43. edge.From("contacts", Contact.Type).
  44. Ref("contact_relationships").
  45. Unique().
  46. Field("contact_id").
  47. Required(),
  48. edge.From("labels", Label.Type).
  49. Ref("label_relationships").
  50. Unique().
  51. Field("label_id").
  52. Required(),
  53. }
  54. }
  55. func (LabelRelationship) Annotations() []schema.Annotation {
  56. return []schema.Annotation{
  57. entsql.WithComments(true),
  58. entsql.Annotation{Table: "label_relationship"},
  59. }
  60. }