From d82e8dd74be3f336f85ee5836bd28238612799ff Mon Sep 17 00:00:00 2001 From: Reza Date: Tue, 29 Oct 2024 13:02:13 +0100 Subject: [PATCH] validator unique columns --- lib/validation/validators.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/validation/validators.go b/lib/validation/validators.go index f184838..b331b68 100644 --- a/lib/validation/validators.go +++ b/lib/validation/validators.go @@ -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 {