当前位置: 首页>>代码示例>>Golang>>正文


Golang DB.AddError方法代码示例

本文整理汇总了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()

}
开发者ID:theplant,项目名称:device_management,代码行数:28,代码来源:validations.go

示例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"))
	}
}
开发者ID:rand99,项目名称:qor-example,代码行数:9,代码来源:color.go

示例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"))
	}
}
开发者ID:qor,项目名称:qor-example,代码行数:9,代码来源:size.go

示例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"))
	}
}
开发者ID:skyview059,项目名称:qor-example,代码行数:9,代码来源:product.go

示例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"))
	}
}
开发者ID:qor,项目名称:validations,代码行数:12,代码来源:validation_test.go

示例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"))
		}
	}
}
开发者ID:umschlag,项目名称:umschlag-api,代码行数:48,代码来源:registry.go

示例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"))
		}
	}
}
开发者ID:umschlag,项目名称:umschlag-api,代码行数:22,代码来源:team.go

示例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"))
		}
	}
}
开发者ID:umschlag,项目名称:umschlag-api,代码行数:70,代码来源:user.go

示例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"))
	}
}
开发者ID:skyview059,项目名称:qor-example,代码行数:5,代码来源:category.go

示例10: Validate

func (user *User) Validate(db *gorm.DB) {
	if user.Name == "invalid" {
		db.AddError(validations.NewError(user, "Name", "invalid user name"))
	}
}
开发者ID:8legd,项目名称:qor-qor,代码行数:5,代码来源:validation_test.go

示例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"))
	}
}
开发者ID:qor,项目名称:qor-example,代码行数:5,代码来源:product.go


注:本文中的github.com/jinzhu/gorm.DB.AddError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。