Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: customize plugin can not update old data #7389

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions backend/impls/dalgorm/dalgorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@ func (d *Dalgorm) Create(entity interface{}, clauses ...dal.Clause) errors.Error
// CreateWithMap insert record to database
func (d *Dalgorm) CreateWithMap(entity interface{}, record map[string]interface{}) errors.Error {
d.unwrapDynamic(&entity, nil)
if record != nil {
if id, ok := record["id"]; ok && id != nil {
var columns []string
for column := range record {
columns = append(columns, column)
}
return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},
DoUpdates: clause.AssignmentColumns(columns),
}).Create(record).Error)
} else {
return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{UpdateAll: true}).Create(record).Error)
}
}
return d.convertGormError(buildTx(d.db, nil).Model(entity).Clauses(clause.OnConflict{UpdateAll: true}).Create(record).Error)
}

Expand Down
Loading