sathishvj sathishvj - 1 year ago 285
SQL Question

golang gorm and mysql: how can I retrieve instance of last added item

I'm using with a mysql backend. I want to retrieve the Id (or the full entity) of the row in the previous Create call.

As in, last-insert-id: (

How can I do this?

Answer Source
type User struct {
  Id int
  Name string

user := User{Name: "jinzhu"}
user.Id -> last insert id
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download