mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: move mutation-set naming to go api (#1123)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -157,9 +157,9 @@ func (m *{{ $mutation }}) ID() (id {{ $n.ID.Type }}, exists bool) {
|
||||
}
|
||||
|
||||
{{ range $f := $n.Fields }}
|
||||
{{ $p := receiver $f.Type.String }}{{ if eq $p "m" }} {{ $p = "value" }} {{ end }}
|
||||
{{ $func := print "Set" $f.StructField }}
|
||||
{{ $const := print $n.Package "." $f.Constant }}
|
||||
{{ $p := receiver $f.Type.String }}{{ if eq $p "m" }} {{ $p = "value" }} {{ end }}
|
||||
{{ $func := $f.MutationSet }}
|
||||
// {{ $func }} sets the {{ $f.Name }} field.
|
||||
func (m *{{ $mutation }}) {{ $func }}({{ $p }} {{ $f.Type }}) {
|
||||
m.{{ $f.BuilderField }} = &{{ $p }}
|
||||
|
||||
@@ -685,7 +685,6 @@ func (t Type) RelatedTypes() []*Type {
|
||||
func ValidSchemaName(name string) error {
|
||||
// schema package is lower-cased (see Type.Package)
|
||||
pkg := strings.ToLower(name)
|
||||
|
||||
if token.Lookup(pkg).IsKeyword() {
|
||||
return fmt.Errorf("schema lowercase name conflicts with Go keyword %q", pkg)
|
||||
}
|
||||
@@ -828,6 +827,17 @@ func (f Field) MutationReset() string {
|
||||
return name
|
||||
}
|
||||
|
||||
// MutationSet returns the method name for setting the field value.
|
||||
// The default name is "Set<FieldName>". If the the method conflicts
|
||||
// with the mutation methods, suffix the method with "Field".
|
||||
func (f Field) MutationSet() string {
|
||||
name := "Set" + f.StructField()
|
||||
if _, ok := mutMethods[name]; ok {
|
||||
name += "Field"
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// IsBool returns true if the field is a bool field.
|
||||
func (f Field) IsBool() bool { return f.Type != nil && f.Type.Type == field.TypeBool }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user