v1.23.5

func Test_update_where(t *testing.T) {
    defer func() {
        if r := recover(); r != nil {
            fmt.Println("panic", r)
        }
    }()

    err := db.Create(&Product{
        Code: time.Now().String(),
    }).Error
    if err != nil {
        fmt.Println(err)
    }

    err = db.Model(&Product{}).Updates(&Product{
        Model: gorm.Model{
            ID: 2,
        },
        Code: "D43",
    }).Error
    if err != nil {
        fmt.Println(err)
    }
}

Update的时候,如果指定了model,不能根据主键生成where条件 Gorm Update的时候,如果指定了model,不能根据主键生成where条件

Gorm Update的时候,如果指定了model,不能根据主键生成where条件

stmt.ReflectValue这里变成了零值,可能是其他地方被重置了 Gorm Update的时候,如果指定了model,不能根据主键生成where条件

Execute的时候是有初始化的 Gorm Update的时候,如果指定了model,不能根据主键生成where条件

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: holicc

直接用Save 或者 db.Model(&Product{Model: gorm.Model{ID: 2}}).Updates(&Product{ Code: "D43"})

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: QianChenglong

直接用Save 或者 db.Model(&Product{Model: gorm.Model{ID: 2}}).Updates(&Product{ Code: "D43"})

绕开没问题,想看下这个是feature还是bug?

Comment From: github-actions[bot]

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking

Comment From: a631807682

It by design, Model means which record you want to update and Updates means which field you want to update