-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Hi again,
According to the ent docs, you can override the id field to be something other than an int.
If you use a Field with just an id field, it fails to compile:
// Fields of the Model.
func (Model) Fields() []ent.Field {
return []ent.Field{
field.String("id"),
}
}
...
❯ go generate ./...
❯ go run -mod=mod main.go
# todo/ent/ogent
ent/ogent/ogent.go:31:61: undefined: CreateModelReq
ent/ogent/ogent.go:93:61: undefined: UpdateModelReq
If you add some other fields, it compiles, but POST fails:
func (Model) Fields() []ent.Field {
return []ent.Field{
field.String("id"),
field.Time("created_at").
Optional().
Default(time.Now),
field.String("name").
Optional(),
}
}
...
❯ curl -X POST http://localhost:8080/models -H "Content-Type: application/json" -d '{"id": "fdsa90fds-890fgs", "name": "test"}'
{"error_message":"NOT NULL constraint failed: models.id"}%
If I'm doing something wrong I apologise. If not, it would be great to get support for overriding IDs.
Any workaround in the meantime?
bartke
Metadata
Metadata
Assignees
Labels
No labels