fixing
This commit is contained in:
parent
7e2b6eba61
commit
b803039c31
@ -60,7 +60,7 @@ type Relationship struct {
|
|||||||
ForeignDBName string
|
ForeignDBName string
|
||||||
AssociationForeignFieldName string
|
AssociationForeignFieldName string
|
||||||
AssociationForeignDBName string
|
AssociationForeignDBName string
|
||||||
JoinTable string
|
JoinTableHandler JoinTableHandlerInterface
|
||||||
AssociationFieldName string
|
AssociationFieldName string
|
||||||
PivotKey string
|
PivotKey string
|
||||||
PivotType string
|
PivotType string
|
||||||
@ -149,6 +149,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer func() {
|
||||||
for _, field := range fields {
|
for _, field := range fields {
|
||||||
if !field.IsIgnored {
|
if !field.IsIgnored {
|
||||||
fieldStruct := field.Struct
|
fieldStruct := field.Struct
|
||||||
@ -208,10 +209,6 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||||||
|
|
||||||
if many2many := gormSettings["MANY2MANY"]; many2many != "" {
|
if many2many := gormSettings["MANY2MANY"]; many2many != "" {
|
||||||
relationship.Kind = "many_to_many"
|
relationship.Kind = "many_to_many"
|
||||||
relationship.JoinTable = many2many
|
|
||||||
relationship.PivotKey = gormSettings["MANY2MANY"]
|
|
||||||
relationship.PivotType = elemType.Name() + "Id"
|
|
||||||
relationship.AssociationFieldName = elemType.Name()
|
|
||||||
|
|
||||||
associationForeignKey := gormSettings["ASSOCIATIONFOREIGNKEY"]
|
associationForeignKey := gormSettings["ASSOCIATIONFOREIGNKEY"]
|
||||||
if associationForeignKey == "" {
|
if associationForeignKey == "" {
|
||||||
@ -222,7 +219,15 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||||||
relationship.ForeignDBName = ToDBName(foreignKey)
|
relationship.ForeignDBName = ToDBName(foreignKey)
|
||||||
relationship.AssociationForeignFieldName = associationForeignKey
|
relationship.AssociationForeignFieldName = associationForeignKey
|
||||||
relationship.AssociationForeignDBName = ToDBName(associationForeignKey)
|
relationship.AssociationForeignDBName = ToDBName(associationForeignKey)
|
||||||
|
|
||||||
|
joinTableHandler := JoinTableHandler{}
|
||||||
|
joinTableHandler.Setup(relationship, many2many, scopeType, elemType)
|
||||||
|
relationship.JoinTableHandler = &joinTableHandler
|
||||||
field.Relationship = relationship
|
field.Relationship = relationship
|
||||||
|
|
||||||
|
relationship.PivotKey = gormSettings["MANY2MANY"]
|
||||||
|
relationship.PivotType = elemType.Name() + "Id"
|
||||||
|
relationship.AssociationFieldName = elemType.Name()
|
||||||
} else {
|
} else {
|
||||||
relationship.Kind = "has_many"
|
relationship.Kind = "has_many"
|
||||||
if foreignField := getForeignField(foreignKey, toScope.GetStructFields()); foreignField != nil {
|
if foreignField := getForeignField(foreignKey, toScope.GetStructFields()); foreignField != nil {
|
||||||
@ -289,6 +294,7 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
|
|||||||
}
|
}
|
||||||
modelStruct.StructFields = append(modelStruct.StructFields, field)
|
modelStruct.StructFields = append(modelStruct.StructFields, field)
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
modelStructs[scopeType] = &modelStruct
|
modelStructs[scopeType] = &modelStruct
|
||||||
|
|
||||||
@ -314,7 +320,7 @@ func (scope *Scope) generateSqlTag(field *StructField) string {
|
|||||||
|
|
||||||
additionalType := sqlSettings["NOT NULL"] + " " + sqlSettings["UNIQUE"]
|
additionalType := sqlSettings["NOT NULL"] + " " + sqlSettings["UNIQUE"]
|
||||||
if value, ok := sqlSettings["DEFAULT"]; ok {
|
if value, ok := sqlSettings["DEFAULT"]; ok {
|
||||||
additionalType = additionalType + "DEFAULT " + value
|
additionalType = additionalType + " DEFAULT " + value
|
||||||
}
|
}
|
||||||
|
|
||||||
if field.IsScanner {
|
if field.IsScanner {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user