moving the check higher up in the if-blocks so it catches all the cases for both types

This commit is contained in:
Matt Schiros 2019-01-18 11:49:16 -08:00
parent d69551bd39
commit b705b0ecbb

View File

@ -274,6 +274,11 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
elemType = elemType.Elem() elemType = elemType.Elem()
} }
if arbitraryConditions, _ := field.TagSettingsGet("ARBITRARY_JOIN_CONDITIONS"); arbitraryConditions != "" {
relationship.ArbitraryJoinConditions = strings.Split(arbitraryConditions, ",")
}
if elemType.Kind() == reflect.Struct { if elemType.Kind() == reflect.Struct {
if many2many, _ := field.TagSettingsGet("MANY2MANY"); many2many != "" { if many2many, _ := field.TagSettingsGet("MANY2MANY"); many2many != "" {
relationship.Kind = "many_to_many" relationship.Kind = "many_to_many"
@ -342,10 +347,6 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
// Check for arbitrary join conditions supplied in the tag // Check for arbitrary join conditions supplied in the tag
if arbitraryConditions, _ := field.TagSettingsGet("ARBITRARY_JOIN_CONDITIONS"); arbitraryConditions != "" {
relationship.ArbitraryJoinConditions = strings.Split(arbitraryConditions, ",")
}
joinTableHandler := JoinTableHandler{} joinTableHandler := JoinTableHandler{}
joinTableHandler.Setup(relationship, ToTableName(many2many), reflectType, elemType) joinTableHandler.Setup(relationship, ToTableName(many2many), reflectType, elemType)
relationship.JoinTableHandler = &joinTableHandler relationship.JoinTableHandler = &joinTableHandler
@ -373,9 +374,6 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
} }
} }
if arbitraryConditions, _ := field.TagSettingsGet("ARBITRARY_JOIN_CONDITIONS"); arbitraryConditions != "" {
relationship.ArbitraryJoinConditions = strings.Split(arbitraryConditions, ",")
}
// if no foreign keys defined with tag // if no foreign keys defined with tag
if len(foreignKeys) == 0 { if len(foreignKeys) == 0 {
@ -477,6 +475,10 @@ func (scope *Scope) GetModelStruct() *ModelStruct {
} }
} }
if arbitraryConditions, _ := field.TagSettingsGet("ARBITRARY_JOIN_CONDITIONS"); arbitraryConditions != "" {
relationship.ArbitraryJoinConditions = strings.Split(arbitraryConditions, ",")
}
// Has One // Has One
{ {
var foreignKeys = tagForeignKeys var foreignKeys = tagForeignKeys