From 1b1dbc0fabde222068f1ab9fcf892a8a8c36fe2b Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 3 Jan 2016 19:47:48 +0800 Subject: [PATCH] Respect customized sql tag when create join table --- scope_private.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scope_private.go b/scope_private.go index cd90c8c2..1d3b57b8 100644 --- a/scope_private.go +++ b/scope_private.go @@ -498,7 +498,10 @@ func (scope *Scope) createJoinTable(field *StructField) { for idx, fieldName := range relationship.ForeignFieldNames { if field, ok := scope.Fields()[fieldName]; ok { value := reflect.Indirect(reflect.New(field.Struct.Type)) - primaryKeySqlType := scope.Dialect().SqlTag(value, 255, false) + primaryKeySqlType := field.TagSettings["TYPE"] + if primaryKeySqlType == "" { + primaryKeySqlType = scope.Dialect().SqlTag(value, 255, false) + } sqlTypes = append(sqlTypes, scope.Quote(relationship.ForeignDBNames[idx])+" "+primaryKeySqlType) primaryKeys = append(primaryKeys, scope.Quote(relationship.ForeignDBNames[idx])) } @@ -507,7 +510,10 @@ func (scope *Scope) createJoinTable(field *StructField) { for idx, fieldName := range relationship.AssociationForeignFieldNames { if field, ok := toScope.Fields()[fieldName]; ok { value := reflect.Indirect(reflect.New(field.Struct.Type)) - primaryKeySqlType := scope.Dialect().SqlTag(value, 255, false) + primaryKeySqlType := field.TagSettings["TYPE"] + if primaryKeySqlType == "" { + primaryKeySqlType = scope.Dialect().SqlTag(value, 255, false) + } sqlTypes = append(sqlTypes, scope.Quote(relationship.AssociationForeignDBNames[idx])+" "+primaryKeySqlType) primaryKeys = append(primaryKeys, scope.Quote(relationship.AssociationForeignDBNames[idx])) }