本文整理汇总了Golang中github.com/jinzhu/gorm.Scope.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang Scope.Get方法的具体用法?Golang Scope.Get怎么用?Golang Scope.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jinzhu/gorm.Scope
的用法示例。
在下文中一共展示了Scope.Get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: validate
func validate(scope *gorm.Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok {
if result, ok := scope.DB().Get(skipValidations); !(ok && result.(bool)) {
scope.CallMethodWithErrorCheck("Validate")
}
}
}
示例2: isDraftMode
func isDraftMode(scope *gorm.Scope) bool {
if draftMode, ok := scope.Get("publish:draft_mode"); ok {
if isDraft, ok := draftMode.(bool); ok && isDraft {
return true
}
}
return false
}
示例3: createPublishEvent
func createPublishEvent(scope *gorm.Scope) {
if _, ok := scope.InstanceGet("publish:creating_publish_event"); ok {
if event, ok := scope.Get(publishEvent); ok {
if event, ok := event.(*PublishEvent); ok {
event.PublishStatus = DIRTY
scope.Err(scope.NewDB().Save(&event).Error)
}
}
}
}
示例4: getModeAndNewScope
func getModeAndNewScope(scope *gorm.Scope) (isProduction bool, clone *gorm.Scope) {
if draftMode, ok := scope.Get("publish:draft_mode"); !ok || !draftMode.(bool) {
if _, ok := scope.InstanceGet("publish:supported_model"); ok {
table := originalTableName(scope.TableName())
clone := scope.New(scope.Value)
clone.Search.Table(table)
return true, clone
}
}
return false, nil
}
示例5: deleteScope
func deleteScope(scope *gorm.Scope) {
if !scope.HasError() {
_, supportedModel := scope.InstanceGet("publish:supported_model")
isDraftMode, ok := scope.Get("publish:draft_mode")
if supportedModel && (ok && isDraftMode.(bool)) {
scope.Raw(
fmt.Sprintf("UPDATE %v SET deleted_at=%v, publish_status=%v %v",
scope.QuotedTableName(),
scope.AddToVars(gorm.NowFunc()),
scope.AddToVars(DIRTY),
scope.CombinedConditionSql(),
))
scope.Exec()
} else {
gorm.Delete(scope)
}
}
}
示例6: validate
func validate(scope *gorm.Scope) {
if _, ok := scope.Get("gorm:update_column"); !ok {
if result, ok := scope.DB().Get(skipValidations); !(ok && result.(bool)) {
if !scope.HasError() {
scope.CallMethod("Validate")
resource := scope.IndirectValue().Interface()
_, validatorErrors := govalidator.ValidateStruct(resource)
if validatorErrors != nil {
if errors, ok := validatorErrors.(govalidator.Errors); ok {
for _, err := range flatValidatorErrors(errors) {
scope.DB().AddError(formattedError(err, resource))
}
} else {
scope.DB().AddError(validatorErrors)
}
}
}
}
}
}