Your Question
FirstOrCreate(gorm@v1.22.4) return RowsAffected with value 1 when record already exist , while FirstOrCreate(gorm@v1.22.2) return RowsAffected with value 0 when record already exist.
is it a new feature change or a bug?
code sample:
var s QaExam
s.ExamID = 10000
s.Title = "xxxx"
rdb := db.FirstOrCreate(&s, &QaExam{ExamID: s.ExamID})
if rdb.Error != nil {
return rdb.Error
}
fmt.Printf("RowsAffected:%d\n", rdb.RowsAffected)
...
The document you expected this should be explained
Expected answer
Comment From: li-jin-gou
hello, it has been fixed in https://github.com/go-gorm/gorm/pull/4826/files. RowsAffected will return tx's RowsAffected, and not db's RowsAffected
Comment From: AzraelJi
how can get db's RowsAffected