本文整理汇总了Golang中github.com/jinzhu/gorm.DB.AddError方法的典型用法代码示例。如果您正苦于以下问题:Golang DB.AddError方法的具体用法?Golang DB.AddError怎么用?Golang DB.AddError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jinzhu/gorm.DB
的用法示例。
在下文中一共展示了DB.AddError方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Validate
func (cOut *ConsumableOut) Validate(db *gorm.DB) {
if cOut.ReportItemID == 0 {
db.AddError(validations.NewError(cOut, "ReportItemID", "消耗品不能为空"))
}
if cOut.ToWhomID == 0 {
db.AddError(validations.NewError(cOut, "ToWhomID", "消耗品使用人不能为空"))
}
if cOut.Quantity <= 0 {
db.AddError(validations.NewError(cOut, "Quantity", "带出消耗品的数量要大于0"))
}
if cOut.ByWhomID == 0 {
db.AddError(validations.NewError(cOut, "ByWhomID", "请选择操作员"))
}
from, to, d, _, _, err := fromToDevice(cOut.ReportItemID, cOut.ToWhomID, "Employee")
if err != nil {
db.AddError(validations.NewError(cOut, "FromReportItemID", err.Error()))
return
}
cOut.DeviceName = d.Name
cOut.ToWhomName = to.HolderName()
cOut.WarehouseName = from.HolderName()
byWhom, _ := holderByIDType(cOut.ByWhomID, "Employee")
cOut.ByWhomName = byWhom.HolderName()
}
示例2: Validate
func (color Color) Validate(db *gorm.DB) {
if strings.TrimSpace(color.Name) == "" {
db.AddError(validations.NewError(color, "Name", "Name can not be empty"))
}
if strings.TrimSpace(color.Code) == "" {
db.AddError(validations.NewError(color, "Code", "Code can not be empty"))
}
}
示例3: Validate
func (size Size) Validate(db *gorm.DB) {
if strings.TrimSpace(size.Name) == "" {
db.AddError(validations.NewError(size, "Name", "Name can not be empty"))
}
if strings.TrimSpace(size.Code) == "" {
db.AddError(validations.NewError(size, "Code", "Code can not be empty"))
}
}
示例4: Validate
func (product Product) Validate(db *gorm.DB) {
if strings.TrimSpace(product.Name) == "" {
db.AddError(validations.NewError(product, "Name", "Name can not be empty"))
}
if strings.TrimSpace(product.Code) == "" {
db.AddError(validations.NewError(product, "Code", "Code can not be empty"))
}
}
示例5: Validate
func (user *User) Validate(db *gorm.DB) {
govalidator.CustomTypeTagMap.Set("uniqEmail", govalidator.CustomTypeValidator(func(email interface{}, context interface{}) bool {
var count int
if db.Model(&User{}).Where("email = ?", email).Count(&count); count == 0 || email == "" {
return true
}
return false
}))
if user.Name == "invalid" {
db.AddError(validations.NewError(user, "Name", "invalid user name"))
}
}
示例6: Validate
// Validate does some validation to be able to store the record.
func (u *Registry) Validate(db *gorm.DB) {
if !govalidator.StringLength(u.Name, "1", "255") {
db.AddError(fmt.Errorf("Name should be longer than 1 and shorter than 255"))
}
if u.Name != "" {
notFound := db.Where(
"name = ?",
u.Name,
).Not(
"id",
u.ID,
).First(
&Registry{},
).RecordNotFound()
if !notFound {
db.AddError(fmt.Errorf("Name is already present"))
}
}
if !govalidator.StringLength(u.Host, "1", "255") {
db.AddError(fmt.Errorf("Host should be longer than 1 and shorter than 255"))
}
if !govalidator.IsRequestURL(u.Host) {
db.AddError(fmt.Errorf(
"Host must be a valid URL",
))
}
if u.Host != "" {
notFound := db.Where(
"host = ?",
u.Host,
).Not(
"id",
u.ID,
).First(
&Registry{},
).RecordNotFound()
if !notFound {
db.AddError(fmt.Errorf("Host is already present"))
}
}
}
示例7: Validate
// Validate does some validation to be able to store the record.
func (u *Team) Validate(db *gorm.DB) {
if !govalidator.StringLength(u.Name, "1", "255") {
db.AddError(fmt.Errorf("Name should be longer than 1 and shorter than 255"))
}
if u.Name != "" {
notFound := db.Where(
"name = ?",
u.Name,
).Not(
"id",
u.ID,
).First(
&Team{},
).RecordNotFound()
if !notFound {
db.AddError(fmt.Errorf("Name is already present"))
}
}
}
示例8: Validate
// Validate does some validation to be able to store the record.
func (u *User) Validate(db *gorm.DB) {
if !govalidator.StringLength(u.Username, "2", "255") {
db.AddError(fmt.Errorf("Username should be longer than 2 and shorter than 255"))
}
if u.Username != "" {
notFound := db.Where(
"username = ?",
u.Username,
).Not(
"id",
u.ID,
).First(
&User{},
).RecordNotFound()
if !notFound {
db.AddError(fmt.Errorf("Username is already present"))
}
}
if u.Hash != "" {
notFound := db.Where(
"hash = ?",
u.Hash,
).Not(
"id",
u.ID,
).First(
&User{},
).RecordNotFound()
if !notFound {
db.AddError(fmt.Errorf("Hash is already present"))
}
}
if !govalidator.IsEmail(u.Email) {
db.AddError(fmt.Errorf(
"Email must be a valid email address",
))
}
if u.Email != "" {
normalized, _ := govalidator.NormalizeEmail(
u.Email,
)
notFound := db.Where(
"email = ?",
normalized,
).Not(
"id",
u.ID,
).First(
&User{},
).RecordNotFound()
if !notFound {
db.AddError(fmt.Errorf("Email is already present"))
}
}
if db.NewRecord(u) {
if !govalidator.StringLength(u.Password, "5", "255") {
db.AddError(fmt.Errorf("Password should be longer than 5 and shorter than 255"))
}
}
}
示例9: Validate
func (category Category) Validate(db *gorm.DB) {
if strings.TrimSpace(category.Name) == "" {
db.AddError(validations.NewError(category, "Name", "Name can not be empty"))
}
}
示例10: Validate
func (user *User) Validate(db *gorm.DB) {
if user.Name == "invalid" {
db.AddError(validations.NewError(user, "Name", "invalid user name"))
}
}
示例11: Validate
func (productImage ProductImage) Validate(db *gorm.DB) {
if strings.TrimSpace(productImage.Title) == "" {
db.AddError(validations.NewError(productImage, "Title", "Tile can not be empty"))
}
}