Skip to content

Commit

Permalink
validator unique columns
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Oct 29, 2024
1 parent 087f418 commit d82e8dd
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/validation/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func uniqueColumnsValidator(match []string, value *generic.Value, stmt *gorm.Sta
}
}
}
of, zero := stmt.Schema.PrioritizedPrimaryField.ValueOf(context.Background(), reflect.ValueOf(stmt.Model))
if !zero {
model = model.Where(stmt.Schema.PrioritizedPrimaryField.DBName+" != ?", of)
}
var c int64
model.Count(&c)
if c > 0 {
Expand Down

0 comments on commit d82e8dd

Please sign in to comment.