Hello.

I want to exclude unmodified fields from the update statement for the "struct" as a result of the "save". For example

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

I want to achieve:

// UPDATE users SET name='jinzhu 2', age=100 WHERE id=111;

instead of

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

I try to get behavior similar to DynamicUpdate annotation in Hibernate. Is it possible, or should I write a plugin for it?

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: zakaria-chahboun

For that reason, Use this way instead

    // update one column
    db.Table("users").Where("id = ?", 1).Update("age", 18)

    // update multiple columns (use maps instead of structs)
    data := map[string]any{
        "name":     "amir",
        "age": 20,
    }
    db.Table("users").Where("id = ?", 1).Updates(data)

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