This commit is contained in:
LIRANCOHEN 2015-03-23 10:22:48 -04:00
parent 7e2b6eba61
commit b803039c31

View File

@ -60,7 +60,7 @@ type Relationship struct {
ForeignDBName string
AssociationForeignFieldName string
AssociationForeignDBName string
JoinTable string
JoinTableHandler JoinTableHandlerInterface
AssociationFieldName string
PivotKey string
PivotType string
@ -149,6 +149,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
}
}
defer func() {
for _, field := range fields {
if !field.IsIgnored {
fieldStruct := field.Struct
@ -208,10 +209,6 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
if many2many := gormSettings["MANY2MANY"]; many2many != "" {
relationship.Kind = "many_to_many"
relationship.JoinTable = many2many
relationship.PivotKey = gormSettings["MANY2MANY"]
relationship.PivotType = elemType.Name() + "Id"
relationship.AssociationFieldName = elemType.Name()
associationForeignKey := gormSettings["ASSOCIATIONFOREIGNKEY"]
if associationForeignKey == "" {
@ -222,7 +219,15 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
relationship.ForeignDBName = ToDBName(foreignKey)
relationship.AssociationForeignFieldName = associationForeignKey
relationship.AssociationForeignDBName = ToDBName(associationForeignKey)
joinTableHandler := JoinTableHandler{}
joinTableHandler.Setup(relationship, many2many, scopeType, elemType)
relationship.JoinTableHandler = &joinTableHandler
field.Relationship = relationship
relationship.PivotKey = gormSettings["MANY2MANY"]
relationship.PivotType = elemType.Name() + "Id"
relationship.AssociationFieldName = elemType.Name()
} else {
relationship.Kind = "has_many"
if foreignField := getForeignField(foreignKey, toScope.GetStructFields()); foreignField != nil {
@ -289,6 +294,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
}
modelStruct.StructFields = append(modelStruct.StructFields, field)
}
}()
modelStructs[scopeType] = &modelStruct