diff --git a/errors.go b/errors.go index 025f5d64..8140fd99 100644 --- a/errors.go +++ b/errors.go @@ -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") ) diff --git a/finisher_api.go b/finisher_api.go index 5bf91af6..bb298c3d 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -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