test:on duplicate update

This commit is contained in:
jinhui.zhou 2025-03-26 12:05:00 +08:00
parent e3fff64cec
commit 529a67dd8f

View File

@ -34,7 +34,7 @@ func TestDuplicateScan(t *testing.T) {
} }
tx := DB.Begin() tx := DB.Begin()
tx = tx.Table(dst.Name()).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "code"}}, DoUpdates: clause.Assignments(map[string]interface{}{"price": gorm.Expr("price + ?", dst.Price)})}).Create(dst) tx = tx.Table(dst.Name()).Clauses(clause.OnConflict{Columns: []clause.Column{{Name: "code"}}, DoUpdates: clause.Assignments(map[string]interface{}{"price": gorm.Expr("price + ?", dst.Price)})}).Create(dst)
p := new(Product) p := new(ProductD)
tx.Debug().Scan(&p) tx.Debug().Scan(&p)
fmt.Printf("tx scan ||%+v\n", p) fmt.Printf("tx scan ||%+v\n", p)
tx.Commit() tx.Commit()