package schema import ( "entgo.io/ent" "entgo.io/ent/dialect/entsql" "entgo.io/ent/schema" "entgo.io/ent/schema/edge" "entgo.io/ent/schema/field" "entgo.io/ent/schema/index" "github.com/suyuan32/simple-admin-common/orm/ent/mixins" ) type LabelRelationship struct { ent.Schema } func (LabelRelationship) Fields() []ent.Field { return []ent.Field{ field.Uint64("label_id").Default(1). Annotations(entsql.WithComments(true)). Comment("标签 ID"), field.Uint64("contact_id").Default(1). Annotations(entsql.WithComments(true)). Comment("联系人 ID"), field.Uint64("organization_id").Optional().Default(1). Comment("机构 ID"). Annotations(entsql.WithComments(true)), } } func (LabelRelationship) Mixin() []ent.Mixin { return []ent.Mixin{ mixins.IDMixin{}, mixins.StatusMixin{}, } } func (LabelRelationship) Indexes() []ent.Index { return []ent.Index{ index.Fields("label_id"), index.Fields("contact_id"), } } func (LabelRelationship) Edges() []ent.Edge { return []ent.Edge{ edge.From("contacts", Contact.Type). Ref("contact_relationships"). Unique(). Field("contact_id"). Required(), edge.From("labels", Label.Type). Ref("label_relationships"). Unique(). Field("label_id"). Required(), } } func (LabelRelationship) Annotations() []schema.Annotation { return []schema.Annotation{ entsql.WithComments(true), entsql.Annotation{Table: "label_relationship"}, } }