/
organization.go
73 lines (65 loc) · 1.37 KB
/
organization.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package schema
import (
"entgo.io/contrib/entproto"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"github.com/tx7do/go-utils/entgo/mixin"
)
// Organization holds the schema definition for the Organization entity.
type Organization struct {
ent.Schema
}
func (Organization) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{
Table: "organization",
Charset: "utf8mb4",
Collation: "utf8mb4_bin",
},
entsql.WithComments(true),
}
}
// Fields of the Organization.
func (Organization) Fields() []ent.Field {
return []ent.Field{
field.String("name").
Comment("名字").
Default("").
MaxLen(128).
Optional().
Nillable(),
field.Uint32("parent_id").
Comment("上一层部门ID").
Optional().
Nillable(),
field.Int32("order_no").
Comment("排序ID").
Default(0).
Annotations(
entproto.Field(6),
).
Optional().
Nillable(),
}
}
// Mixin of the Organization.
func (Organization) Mixin() []ent.Mixin {
return []ent.Mixin{
mixin.AutoIncrementId{},
mixin.Time{},
mixin.SwitchStatus{},
mixin.CreateBy{},
mixin.Remark{},
}
}
// Edges of the Organization.
func (Organization) Edges() []ent.Edge {
return []ent.Edge{
edge.
To("children", Organization.Type).
From("parent").Unique().Field("parent_id"),
}
}