Add error gorm.ErrInvalidData

This commit is contained in:
Jinzhu 2020-08-18 18:00:36 +08:00
parent dc48e04896
commit 50826742fd
4 changed files with 15 additions and 0 deletions

View File

@ -309,6 +309,8 @@ func ConvertToCreateValues(stmt *gorm.Statement) (values clause.Values) {
}
}
}
default:
stmt.AddError(gorm.ErrInvalidData)
}
}

View File

@ -252,6 +252,8 @@ func ConvertToAssignments(stmt *gorm.Statement) (set clause.Set) {
}
}
}
default:
stmt.AddError(gorm.ErrInvalidData)
}
}

View File

@ -19,6 +19,8 @@ var (
ErrPrimaryKeyRequired = errors.New("primary key required")
// ErrModelValueRequired model value required
ErrModelValueRequired = errors.New("model value required")
// ErrInvalidData unsupported data
ErrInvalidData = errors.New("unsupported data")
// ErrUnsupportedDriver unsupported driver
ErrUnsupportedDriver = errors.New("unsupported driver")
// ErrRegistered registered

View File

@ -334,6 +334,15 @@ func TestSelectWithUpdateWithMap(t *testing.T) {
AssertObjEqual(t, result2, result, "Name", "Account", "Toys", "Manager", "ManagerID", "Languages")
}
func TestWithUpdateWithInvalidMap(t *testing.T) {
user := *GetUser("update_with_invalid_map", Config{})
DB.Create(&user)
if err := DB.Model(&user).Updates(map[string]string{"name": "jinzhu"}).Error; !errors.Is(err, gorm.ErrInvalidData) {
t.Errorf("should returns error for unsupported updating data")
}
}
func TestOmitWithUpdate(t *testing.T) {
user := *GetUser("omit_update", Config{Account: true, Pets: 3, Toys: 3, Company: true, Manager: true, Team: 3, Languages: 3, Friends: 4})
DB.Create(&user)