mirror of
https://github.com/ent/ent.git
synced 2026-03-05 19:35:23 +03:00
entc/gen: handle default funcs in runtime tempalte (#1102)
This commit is contained in:
@@ -208,7 +208,12 @@ func (b *stringBuilder) Default(s string) *stringBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// DefaultFunc sets the default value generating function of the field.
|
||||
// DefaultFunc sets the function that is applied to set the default value
|
||||
// of the field on creation. For example:
|
||||
//
|
||||
// field.String("cuid").
|
||||
// DefaultFunc(cuid.New)
|
||||
//
|
||||
func (b *stringBuilder) DefaultFunc(fn func() string) *stringBuilder {
|
||||
b.desc.Default = fn
|
||||
return b
|
||||
@@ -490,15 +495,14 @@ func (b *bytesBuilder) Default(v []byte) *bytesBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// DefaultFunc sets the function that is applied to set default value
|
||||
// DefaultFunc sets the function that is applied to set the default value
|
||||
// of the field on creation. For example:
|
||||
//
|
||||
// field.Bytes("cuid").
|
||||
// DefaultFunc(cuid.New)
|
||||
//
|
||||
func (b *bytesBuilder) DefaultFunc(v func() []byte) *bytesBuilder {
|
||||
b.desc.Default = v
|
||||
|
||||
func (b *bytesBuilder) DefaultFunc(fn func() []byte) *bytesBuilder {
|
||||
b.desc.Default = fn
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -183,8 +183,7 @@ func TestBytes(t *testing.T) {
|
||||
assert.True(t, fd.Info.Nillable)
|
||||
assert.True(t, fd.Info.ValueScanner())
|
||||
|
||||
fd = field.
|
||||
Bytes("uuid").
|
||||
fd = field.Bytes("uuid").
|
||||
GoType(&uuid.UUID{}).
|
||||
DefaultFunc(func() []byte {
|
||||
return []byte("{}")
|
||||
|
||||
Reference in New Issue
Block a user