Merge 546069e74cef62c8f5a32c8146fcc6541b66f6e6 into 9acaa33324bbcc78239a1c913d4f1292c12177b9

This commit is contained in:
Dan Hardman 2017-05-10 22:04:48 +00:00 committed by GitHub
commit 9509522d16
2 changed files with 6 additions and 0 deletions

View File

@ -27,6 +27,10 @@ func beforeDeleteCallback(scope *Scope) {
// deleteCallback used to delete data from database or set deleted_at to current time (when using with soft delete) // deleteCallback used to delete data from database or set deleted_at to current time (when using with soft delete)
func deleteCallback(scope *Scope) { func deleteCallback(scope *Scope) {
if scope.PrimaryKeyZero() {
scope.db.AddError(ErrNonSpecificDelete)
}
if !scope.HasError() { if !scope.HasError() {
var extraOption string var extraOption string
if str, ok := scope.Get("gorm:delete_option"); ok { if str, ok := scope.Get("gorm:delete_option"); ok {

View File

@ -6,6 +6,8 @@ import (
) )
var ( var (
// ErrNonSpecificDelete no primary key specified for delete, happens when you try to `Delete` a record without a primary key set
ErrNonSpecificDelete = errors.New("no primary key specified for delete")
// ErrRecordNotFound record not found error, happens when haven't find any matched data when looking up with a struct // ErrRecordNotFound record not found error, happens when haven't find any matched data when looking up with a struct
ErrRecordNotFound = errors.New("record not found") ErrRecordNotFound = errors.New("record not found")
// ErrInvalidSQL invalid SQL error, happens when you passed invalid SQL // ErrInvalidSQL invalid SQL error, happens when you passed invalid SQL