How can I retrieve instance of last added item
type User struct {
Id int
Name string
}
user := User{Name: "jinzhu"}
db.Save(&user)
// user.Id is set to last insert id
Try as follows
type User struct {
Id int `gorm:"column:id; PRIMARY_KEY" json:"id"`
Name string `gorm:"column:name" json:"name"`
}
user := User{Name: "Andy"}
db.Save(&user)
// user.Id is set to last insert id