Gorm update query doubt?

The

gorm document has an update example: http://gorm.io/zh_CN/docs/upd.

db.First(&user)

user.Name = "jinzhu 2"
user.Age = 100
db.Save(&user)

//// UPDATE users SET name="jinzhu 2", age=100, birthday="2016-01-01", updated_at = "2013-11-17 21:34:10" WHERE id=111;

question:
the last line of comment, where did id=111 come from? The user above has an id field by default. Will the gorm framework automatically place this id field in the id of the sql query statement? What if it is not id, but uuid, can only be queried manually with where?

Mar.04,2022

db.First is the first record obtained, which is equivalent to the sql statement limit 1
when the user variable is bound. In fact, the value of user.id already exists in the user object, and the value is 111
. So if the user object is directly save at this time, it is equivalent to update the record id=111.


Yes, the model of ORM will automatically generate id, if uuid needs to be processed manually


.

if you use gorm.Model, it will be filled automatically, if it is uuid

type User    struct {

    UUID string `gorm:"primary_key"`

}

will also help you automatically specify it as

of uuid.
Menu