label_relationship.go 1.4 KB

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