diff --git a/.scaffold/model/scaffold.yaml b/.scaffold/model/scaffold.yaml index 0e78b44..028d2fa 100644 --- a/.scaffold/model/scaffold.yaml +++ b/.scaffold/model/scaffold.yaml @@ -14,6 +14,20 @@ questions: message: "What is the name of the model? (PascalCase)" required: true + - name: "by_group" + prompt: + confirm: "Include a Group Edge? (group_id -> id)" + required: true + rewrites: - from: 'templates/model.go' - to: 'backend/internal/data/ent/schema/{{ lower .Scaffold.model }}.go' \ No newline at end of file + to: 'backend/internal/data/ent/schema/{{ lower .Scaffold.model }}.go' + +inject: + - name: "Insert Groups Edge" + path: 'backend/internal/data/ent/schema/group.go' + at: // $scaffold_edge + template: | + {{- if .Scaffold.by_group -}} + owned("{{ lower .Scaffold.model }}s", {{ .Scaffold.model }}.Type), + {{- end -}} diff --git a/.scaffold/model/templates/model.go b/.scaffold/model/templates/model.go index 93f65af..b73ac16 100644 --- a/.scaffold/model/templates/model.go +++ b/.scaffold/model/templates/model.go @@ -13,6 +13,9 @@ type {{ .Scaffold.model }} struct { func ({{ .Scaffold.model }}) Mixin() []ent.Mixin { return []ent.Mixin{ mixins.BaseMixin{}, + {{- if .Scaffold.by_group }} + GroupMixin{ref: "{{ snakecase .Scaffold.model }}s"}, + {{- end }} } } diff --git a/backend/internal/data/ent/schema/group.go b/backend/internal/data/ent/schema/group.go index 49ee54d..6f758ab 100644 --- a/backend/internal/data/ent/schema/group.go +++ b/backend/internal/data/ent/schema/group.go @@ -49,6 +49,7 @@ func (Group) Edges() []ent.Edge { owned("documents", Document.Type), owned("invitation_tokens", GroupInvitationToken.Type), owned("notifiers", Notifier.Type), + // $scaffold_edge } } diff --git a/backend/internal/data/ent/schema/test.go b/backend/internal/data/ent/schema/test.go new file mode 100755 index 0000000..2253401 --- /dev/null +++ b/backend/internal/data/ent/schema/test.go @@ -0,0 +1,38 @@ +package schema + +import ( + "entgo.io/ent" + + "github.com/hay-kot/homebox/backend/internal/data/ent/schema/mixins" +) + +type Test struct { + ent.Schema +} + +func (Test) Mixin() []ent.Mixin { + return []ent.Mixin{ + mixins.BaseMixin{}, + GroupMixin{ref: "tests"}, + } +} + +// Fields of the Test. +func (Test) Fields() []ent.Field { + return []ent.Field{ + // field.String("name"). + } +} + +// Edges of the Test. +func (Test) Edges() []ent.Edge { + return []ent.Edge{ + // edge.From("group", Group.Type). + } +} + +func (Test) Indexes() []ent.Index { + return []ent.Index{ + // index.Fields("token"), + } +} \ No newline at end of file