fix: add error for multiple rows found
This commit is contained in:
parent
4386e52264
commit
389a302d38
@ -51,4 +51,6 @@ var (
|
|||||||
ErrForeignKeyViolated = errors.New("violates foreign key constraint")
|
ErrForeignKeyViolated = errors.New("violates foreign key constraint")
|
||||||
// ErrCheckConstraintViolated occurs when there is a check constraint violation
|
// ErrCheckConstraintViolated occurs when there is a check constraint violation
|
||||||
ErrCheckConstraintViolated = errors.New("violates check constraint")
|
ErrCheckConstraintViolated = errors.New("violates check constraint")
|
||||||
|
// ErrMultipleRecordsFound occurs when more than one record found with Only
|
||||||
|
ErrMultipleRecordsFound = errors.New("multiple records found")
|
||||||
)
|
)
|
||||||
|
@ -181,7 +181,7 @@ func (db *DB) Only(dest interface{}, conds ...interface{}) (tx *DB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if count > 1 {
|
if count > 1 {
|
||||||
findTx.AddError(fmt.Errorf("expected exactly one record, but found %d", count))
|
findTx.AddError(ErrMultipleRecordsFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
return findTx
|
return findTx
|
||||||
|
Loading…
x
Reference in New Issue
Block a user