entc/gen: add edge method for getting mutation-remove in templates

This commit is contained in:
Ariel Mashraki
2021-04-08 15:22:48 +03:00
committed by Ariel Mashraki
parent bd246f28dc
commit 9090c103be
3 changed files with 9 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@@ -282,9 +282,8 @@ func (m *{{ $mutation }}) ID() (id {{ $n.ID.Type }}, exists bool) {
{{ if not $e.Unique }}
{{ $p := lower (printf "%.1s" $e.Type.Name) }}
{{ $idsFunc := print "Remove" (singular $e.Name | pascal) "IDs" }}
// {{ $idsFunc }} removes the "{{ $e.Name }}" edge to the {{ $e.Type.Name }} entity by IDs.
func (m *{{ $mutation }}) {{ $idsFunc }}(ids ...{{ $e.Type.ID.Type }}) {
// {{ $e.MutationRemove }} removes the "{{ $e.Name }}" edge to the {{ $e.Type.Name }} entity by IDs.
func (m *{{ $mutation }}) {{ $e.MutationRemove }}(ids ...{{ $e.Type.ID.Type }}) {
if m.removed{{ $e.BuilderField }} == nil {
m.removed{{ $e.BuilderField }} = make(map[{{ $e.Type.ID.Type }}]struct{})
}

View File

@@ -1396,6 +1396,11 @@ func (e Edge) MutationClear() string {
return name
}
// MutationRemove returns the method name for removing edge ids.
func (e Edge) MutationRemove() string {
return "Remove" + pascal(rules.Singularize(e.Name)) + "IDs"
}
// MutationCleared returns the method name for indicating if the edge
// was cleared in the mutation. The default name is "<EdgeName>Cleared".
// If the the method conflicts with the mutation methods, add "Edge" the