I got a little confused with the default behavior when creating a record for the gorm package.
city := models.City
if err := databases.DBGORM.Set("gorm:insert_option", "RETURNING *").Create(&city).Error; err != nil {
fmt.Println(err.Error())
}
In logs I see such SQL query:
INSERT INTO "my_scheme"."city" ("created_at","updated_at","deleted_at","name","country") VALUES ('2020-05-19 23:45:18','2020-05-19 23:45:18',NULL,'New York','USA') RETURNING * RETURNING "my_scheme"."city"."id"
As you can see from the query I have a double RETURNING clause which is not correct and raise an error.
Adding an id at the end of an SQL query seems to be the default behavior of the Create method. How can I change this behavior?
models.go:
package models
import (
"my_app/proto"
"time"
)
type City struct {
Id uint64
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
proto.City
}
func (City) TableName() string {
return "my_scheme.city"
}