mirror of https://github.com/go-gorm/gorm.git
Add error gorm.ErrInvalidData
This commit is contained in:
parent
dc48e04896
commit
50826742fd
|
@ -309,6 +309,8 @@ func ConvertToCreateValues(stmt *gorm.Statement) (values clause.Values) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
stmt.AddError(gorm.ErrInvalidData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,6 +252,8 @@ func ConvertToAssignments(stmt *gorm.Statement) (set clause.Set) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
stmt.AddError(gorm.ErrInvalidData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ var (
|
||||||
ErrPrimaryKeyRequired = errors.New("primary key required")
|
ErrPrimaryKeyRequired = errors.New("primary key required")
|
||||||
// ErrModelValueRequired model value required
|
// ErrModelValueRequired model value required
|
||||||
ErrModelValueRequired = errors.New("model value required")
|
ErrModelValueRequired = errors.New("model value required")
|
||||||
|
// ErrInvalidData unsupported data
|
||||||
|
ErrInvalidData = errors.New("unsupported data")
|
||||||
// ErrUnsupportedDriver unsupported driver
|
// ErrUnsupportedDriver unsupported driver
|
||||||
ErrUnsupportedDriver = errors.New("unsupported driver")
|
ErrUnsupportedDriver = errors.New("unsupported driver")
|
||||||
// ErrRegistered registered
|
// ErrRegistered registered
|
||||||
|
|
|
@ -334,6 +334,15 @@ func TestSelectWithUpdateWithMap(t *testing.T) {
|
||||||
AssertObjEqual(t, result2, result, "Name", "Account", "Toys", "Manager", "ManagerID", "Languages")
|
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) {
|
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})
|
user := *GetUser("omit_update", Config{Account: true, Pets: 3, Toys: 3, Company: true, Manager: true, Team: 3, Languages: 3, Friends: 4})
|
||||||
DB.Create(&user)
|
DB.Create(&user)
|
||||||
|
|
Loading…
Reference in New Issue