enum Default() should support non-string GoType
- Dominant language
- Go
- Stars
- 17.2k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
- [x] I have searched the [issues](https://github.com/ent/ent/issues) of this repository and believe that this is not a duplicate.
## Summary 💡
enum Default() should take an `interface{}` parameter to support non-string GoType enum.
```go
// Default sets the default value of the field.
func (b *enumBuilder) Default(value interface{}) *enumBuilder {
b.desc.Default = value
return b
}
```
## Motivation 🔦
schema definition:
```go
type DeliveryBy uint8
const (
DeliveryByUnknown DeliveryBy = iota
DeliveryByShop
)
// implement the EnumValues and ValueScanner interfaces
func (Shop) Fields() []ent.Field {
return []ent.Field{
field.Enum("delivery_by").GoType(DeliveryBy(0)).Default(DeliveryByShop.String()),
}
}
```
generates a string constant causing compile error:
```go
const DefaultDeliveryBy DeliveryBy = "shop"
```
> ent/shop/shop.go:123:7: cannot use "shop" (type untyped string) as type DeliveryBy
Thanks for your brilliant library!
Contributor guide
Assessment
This issue has not been assessed yet.