mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
schema/field: add DefaultFunc for numeric types and add support for it in entc (#1153)
* entc/load: allow defaultfuncs on numeric types * schema/field: add DefaultFunc on numeric types * docs: document DefaultFunc better * chore: update generated files * pr: address issues * docs: updates on faq, address requested changes
This commit is contained in:
@@ -108,6 +108,13 @@ func (b *{{ $builder }}) Default(i {{ $t }}) *{{ $builder }} {
|
||||
return b
|
||||
}
|
||||
|
||||
// DefaultFunc sets the function that is applied to set the default value
|
||||
// of the field on creation.
|
||||
func (b *{{ $builder }}) DefaultFunc(fn interface{}) *{{ $builder }} {
|
||||
b.desc.Default = fn
|
||||
return b
|
||||
}
|
||||
|
||||
// Nillable indicates that this field is a nillable.
|
||||
// Unlike "Optional" only fields, "Nillable" fields are pointers in the generated field.
|
||||
func (b *{{ $builder }}) Nillable() *{{ $builder }} {
|
||||
@@ -191,6 +198,9 @@ func (b *{{ $builder }}) Annotations(annotations ...schema.Annotation) *{{ $buil
|
||||
|
||||
// Descriptor implements the ent.Field interface by returning its descriptor.
|
||||
func (b *{{ $builder }}) Descriptor() *Descriptor {
|
||||
if b.desc.Default != nil {
|
||||
b.desc.checkDefaultFunc({{ $t }}Type)
|
||||
}
|
||||
return b.desc
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user