fix: add error for multiple rows found

This commit is contained in:
moein 2025-05-05 15:00:57 +03:30
parent 4386e52264
commit 389a302d38
No known key found for this signature in database
GPG Key ID: 5D04361D895D9E7E
2 changed files with 3 additions and 1 deletions

View File

@ -51,4 +51,6 @@ var (
ErrForeignKeyViolated = errors.New("violates foreign key constraint")
// ErrCheckConstraintViolated occurs when there is a check constraint violation
ErrCheckConstraintViolated = errors.New("violates check constraint")
// ErrMultipleRecordsFound occurs when more than one record found with Only
ErrMultipleRecordsFound = errors.New("multiple records found")
)

View File

@ -181,7 +181,7 @@ func (db *DB) Only(dest interface{}, conds ...interface{}) (tx *DB) {
}
if count > 1 {
findTx.AddError(fmt.Errorf("expected exactly one record, but found %d", count))
findTx.AddError(ErrMultipleRecordsFound)
}
return findTx