Formatting code with gomt

This commit is contained in:
joe-at-startupmedia 2017-10-10 18:20:56 +00:00 committed by Jinzhu
parent 9235b47ea2
commit 9f409820df

View File

@ -11,34 +11,34 @@ func commitOrRollbackTransactionCallback(scope *Scope) {
} }
func saveFieldAsAssociation(scope *Scope, field *Field) (bool, *Relationship) { func saveFieldAsAssociation(scope *Scope, field *Field) (bool, *Relationship) {
if scope.changeableField(field) && !field.IsBlank && !field.IsIgnored { if scope.changeableField(field) && !field.IsBlank && !field.IsIgnored {
if value, ok := field.TagSettings["SAVE_ASSOCIATIONS"]; !ok || (value != "false" && value != "skip") { if value, ok := field.TagSettings["SAVE_ASSOCIATIONS"]; !ok || (value != "false" && value != "skip") {
return true, field.Relationship return true, field.Relationship
} }
return false, field.Relationship return false, field.Relationship
} }
return false, nil return false, nil
} }
func saveBeforeAssociationsCallback(scope *Scope) { func saveBeforeAssociationsCallback(scope *Scope) {
for _, field := range scope.Fields() { for _, field := range scope.Fields() {
ok, relationship := saveFieldAsAssociation(scope, field); ok, relationship := saveFieldAsAssociation(scope, field)
if relationship != nil && relationship.Kind == "belongs_to" { if relationship != nil && relationship.Kind == "belongs_to" {
fieldValue := field.Field.Addr().Interface() fieldValue := field.Field.Addr().Interface()
if ok && scope.shouldSaveAssociations() { if ok && scope.shouldSaveAssociations() {
scope.Err(scope.NewDB().Save(fieldValue).Error) scope.Err(scope.NewDB().Save(fieldValue).Error)
} }
if len(relationship.ForeignFieldNames) != 0 { if len(relationship.ForeignFieldNames) != 0 {
// set value's foreign key // set value's foreign key
for idx, fieldName := range relationship.ForeignFieldNames { for idx, fieldName := range relationship.ForeignFieldNames {
associationForeignName := relationship.AssociationForeignDBNames[idx] associationForeignName := relationship.AssociationForeignDBNames[idx]
if foreignField, ok := scope.New(fieldValue).FieldByName(associationForeignName); ok { if foreignField, ok := scope.New(fieldValue).FieldByName(associationForeignName); ok {
scope.Err(scope.SetColumn(fieldName, foreignField.Field.Interface())) scope.Err(scope.SetColumn(fieldName, foreignField.Field.Interface()))
} }
} }
} }
} }
} }
} }
func saveAfterAssociationsCallback(scope *Scope) { func saveAfterAssociationsCallback(scope *Scope) {