mirror of
https://github.com/hay-kot/homebox.git
synced 2024-11-22 08:35:43 +00:00
support group edges via scaffold
This commit is contained in:
parent
9fa4da819f
commit
737007b156
4 changed files with 57 additions and 1 deletions
|
@ -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'
|
||||
|
||||
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 -}}
|
||||
|
|
|
@ -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 }}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ func (Group) Edges() []ent.Edge {
|
|||
owned("documents", Document.Type),
|
||||
owned("invitation_tokens", GroupInvitationToken.Type),
|
||||
owned("notifiers", Notifier.Type),
|
||||
// $scaffold_edge
|
||||
}
|
||||
}
|
||||
|
||||
|
|
38
backend/internal/data/ent/schema/test.go
Executable file
38
backend/internal/data/ent/schema/test.go
Executable file
|
@ -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"),
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue