diff --git a/dialect_common.go b/dialect_common.go index d549510ccc..f80255ad85 100644 --- a/dialect_common.go +++ b/dialect_common.go @@ -43,6 +43,8 @@ func (commonDialect) Quote(key string) string { func (s *commonDialect) fieldCanAutoIncrement(field *StructField) bool { if value, ok := field.TagSettingsGet("AUTO_INCREMENT"); ok { return strings.ToLower(value) != "false" + } else if value, ok := field.TagSettingsGet("AUTOINCREMENT"); ok { + return strings.ToLower(value) != "false" } return field.IsPrimaryKey } diff --git a/model_struct.go b/model_struct.go index ecadf3727e..b5e2f260c6 100644 --- a/model_struct.go +++ b/model_struct.go @@ -305,6 +305,8 @@ func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) * associationForeignKeys = strings.Split(foreignKey, ",") } else if foreignKey, _ := field.TagSettingsGet("ASSOCIATIONFOREIGNKEY"); foreignKey != "" { associationForeignKeys = strings.Split(foreignKey, ",") + } else if foreignKey, _ := field.TagSettingsGet("REFERENCES"); foreignKey != "" { + associationForeignKeys = strings.Split(foreignKey, ",") } for elemType.Kind() == reflect.Slice || elemType.Kind() == reflect.Ptr { @@ -318,8 +320,11 @@ func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) * { // Foreign Keys for Source joinTableDBNames := []string{} + // Compatibility with GORM v2 if foreignKey, _ := field.TagSettingsGet("JOINTABLE_FOREIGNKEY"); foreignKey != "" { joinTableDBNames = strings.Split(foreignKey, ",") + } else if foreignKey, _ := field.TagSettingsGet("JOINFOREIGNKEY"); foreignKey != "" { + joinTableDBNames = strings.Split(foreignKey, ",") } // if no foreign keys defined with tag @@ -351,6 +356,8 @@ func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) * if foreignKey, _ := field.TagSettingsGet("ASSOCIATION_JOINTABLE_FOREIGNKEY"); foreignKey != "" { associationJoinTableDBNames = strings.Split(foreignKey, ",") + } else if foreignKey, _ := field.TagSettingsGet("JOINTABLEREFERENCES"); foreignKey != "" { + associationJoinTableDBNames = strings.Split(foreignKey, ",") } // if no association foreign keys defined with tag @@ -395,7 +402,21 @@ func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) * relationship.PolymorphicType = polymorphicType.Name relationship.PolymorphicDBName = polymorphicType.DBName // if Dog has multiple set of toys set name of the set (instead of default 'dogs') - if value, ok := field.TagSettingsGet("POLYMORPHIC_VALUE"); ok { + + // Compatibility with GORM v2 + + var value string + var ok bool + + if v1, ok1 := field.TagSettingsGet("POLYMORPHIC_VALUE"); ok1 { + value = v1 + ok = ok1 + } else if v2, ok2 := field.TagSettingsGet("POLYMORPHICVALUE"); ok2 { + value = v2 + ok = ok2 + } + + if ok { relationship.PolymorphicValue = value } else { relationship.PolymorphicValue = scope.TableName() @@ -489,6 +510,8 @@ func (scope *Scope) getModelStruct(rootScope *Scope, allFields []*StructField) * tagAssociationForeignKeys = strings.Split(foreignKey, ",") } else if foreignKey, _ := field.TagSettingsGet("ASSOCIATIONFOREIGNKEY"); foreignKey != "" { tagAssociationForeignKeys = strings.Split(foreignKey, ",") + } else if foreignKey, _ := field.TagSettingsGet("REFERENCES"); foreignKey != "" { + tagAssociationForeignKeys = strings.Split(foreignKey, ",") } if polymorphic, _ := field.TagSettingsGet("POLYMORPHIC"); polymorphic != "" {