Issue

When updating a record, GORM does not use all defined primary keys. Because some of the primary keys are disregarded, more records are updated than expected.

Example

Users table

Name and Age are defined as primary keys. | Name | Age | Cool | |----------|:-------------:|------:| | jinzhu | 20 | no| | jinzhu | 21 | no| | john | 22 | no |

GORM model

type User struct { 
  Name string `gorm:"primaryKey"`
  Age string `gorm:"primaryKey"`
  Cool string
}

Query

Find the first user named jinzhu and update the cool attribute to yes.

user := User{}
db.Where(&User{Name: "jinzhu"}).First(&user)
db.Model(&user).UpdateColumn("cool", "yes")

Expected result

Expected GORM to update the cool attribute of the record found above. After the update the state of the data is expected to be:

Name Age Cool
jinzhu 20 yes
jinzhu 21 no
john 22 no

Actual result

GORM updated the cool attribute of all records that have the name: jinzhu. The age primary key was disregarded. After the update the state of the data is:

Name Age Cool
jinzhu 20 yes
jinzhu 21 yes
john 22 no

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