From f624f071296ba18958d1f3941d160dde2d78c117 Mon Sep 17 00:00:00 2001 From: Zeal Date: Tue, 5 Sep 2017 22:17:19 +0800 Subject: [PATCH] add tag ForeignColumn and AssociationForeignColumn for because of anonymous have no name of type --- model_struct.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/model_struct.go b/model_struct.go index 315028c4..0925fbbb 100644 --- a/model_struct.go +++ b/model_struct.go @@ -276,7 +276,10 @@ func (scope *Scope) GetModelStruct() *ModelStruct { // source foreign keys (db names) relationship.ForeignFieldNames = append(relationship.ForeignFieldNames, foreignField.DBName) // join table foreign keys for source - joinTableDBName := ToDBName(reflectType.Name()) + "_" + foreignField.DBName + joinTableDBName := ToDBName(field.TagSettings["FOREIGNCOLUMN"]) + if len(joinTableDBName) == 0 { + joinTableDBName = ToDBName(reflectType.Name()) + "_" + foreignField.DBName + } relationship.ForeignDBNames = append(relationship.ForeignDBNames, joinTableDBName) } } @@ -293,7 +296,10 @@ func (scope *Scope) GetModelStruct() *ModelStruct { // association foreign keys (db names) relationship.AssociationForeignFieldNames = append(relationship.AssociationForeignFieldNames, field.DBName) // join table foreign keys for association - joinTableDBName := ToDBName(elemType.Name()) + "_" + field.DBName + joinTableDBName := ToDBName(field.TagSettings["ASSOCIATIONFOREIGNCOLUMN"]) + if len(joinTableDBName) == 0 { + joinTableDBName = ToDBName(reflectType.Name()) + "_" + field.DBName + } relationship.AssociationForeignDBNames = append(relationship.AssociationForeignDBNames, joinTableDBName) } }