Skip to content

Commit

Permalink
hotfix go-gorm#100
Browse files Browse the repository at this point in the history
  • Loading branch information
ddadaal committed Jan 16, 2024
1 parent b8d91cb commit b8fb748
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ func Create(db *gorm.DB) {
onConflict, hasConflict = c.Expression.(clause.OnConflict)
)

if hasConflict {
if len(db.Statement.Schema.PrimaryFields) > 0 {
columnsMap := map[string]bool{}
for _, column := range values.Columns {
columnsMap[column.Name] = true
}

for _, field := range db.Statement.Schema.PrimaryFields {
if _, ok := columnsMap[field.DBName]; !ok {
hasConflict = false
}
}
} else {
hasConflict = false
}
}
// if hasConflict {
// if len(db.Statement.Schema.PrimaryFields) > 0 {
// columnsMap := map[string]bool{}
// for _, column := range values.Columns {
// columnsMap[column.Name] = true
// }

// for _, field := range db.Statement.Schema.PrimaryFields {
// if _, ok := columnsMap[field.DBName]; !ok {
// hasConflict = false
// }
// }
// } else {
// hasConflict = false
// }
// }

if hasConflict {
MergeCreate(db, onConflict, values)
Expand Down Expand Up @@ -157,10 +157,10 @@ func MergeCreate(db *gorm.DB, onConflict clause.OnConflict, values clause.Values
db.Statement.WriteString(") ON ")

var where clause.Where
for _, field := range db.Statement.Schema.PrimaryFields {
for _, field := range onConflict.Columns {
where.Exprs = append(where.Exprs, clause.Eq{
Column: clause.Column{Table: db.Statement.Table, Name: field.DBName},
Value: clause.Column{Table: "excluded", Name: field.DBName},
Column: clause.Column{Table: db.Statement.Table, Name: field.Name},
Value: clause.Column{Table: "excluded", Name: field.Name},
})
}
where.Build(db.Statement)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module gorm.io/driver/sqlserver
module github.com/ddadaal/gorm-sqlserver

go 1.14

Expand Down
2 changes: 1 addition & 1 deletion migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
"testing"

"gorm.io/driver/sqlserver"
sqlserver "github.com/ddadaal/gorm-sqlserver"
"gorm.io/gorm"
)

Expand Down

0 comments on commit b8fb748

Please sign in to comment.