mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: expose edge mutation setters for external templates (#1032)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -254,8 +254,7 @@ func (m *{{ $mutation }}) ID() (id {{ $n.ID.Type }}, exists bool) {
|
||||
|
||||
|
||||
{{ range $e := $n.Edges }}
|
||||
{{ $op := "add" }}{{ if $e.Unique }}{{ $op = "set" }}{{ end }}
|
||||
{{ $idsFunc := print (pascal $op) (singular $e.Name | pascal) "IDs" }}{{ if $e.Unique }}{{ $idsFunc = print (pascal $op) (pascal $e.Name) "ID" }}{{ end }}
|
||||
{{ $op := "add" }}{{ $idsFunc := $e.MutationAdd }}{{ if $e.Unique }}{{ $op = "set" }}{{ $idsFunc = $e.MutationSet }}{{ end }}
|
||||
// {{ $idsFunc }} {{ $op }}s the {{ $e.Name }} edge to {{ $e.Type.Name }} by id{{ if not $e.Unique }}s{{ end }}.
|
||||
func (m *{{ $mutation }}) {{ $idsFunc }}({{ if $e.Unique }}id{{ else }}ids ...{{ end }} {{ $e.Type.ID.Type }}) {
|
||||
{{- if $e.Unique }}
|
||||
|
||||
@@ -1148,6 +1148,16 @@ func (e Edge) OwnFK() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// MutationSet returns the method name for setting the edge id.
|
||||
func (e Edge) MutationSet() string {
|
||||
return "Set" + pascal(e.Name) + "ID"
|
||||
}
|
||||
|
||||
// MutationAdd returns the method name for adding edge ids.
|
||||
func (e Edge) MutationAdd() string {
|
||||
return "Add" + pascal(rules.Singularize(e.Name)) + "IDs"
|
||||
}
|
||||
|
||||
// MutationReset returns the method name for resetting the edge value.
|
||||
// The default name is "Reset<EdgeName>". If the the method conflicts
|
||||
// with the mutation methods, suffix the method with "Edge".
|
||||
|
||||
Reference in New Issue
Block a user