From b705b0ecbbc6a6ca04d04ea0fc7c3bc2dc4bb15a Mon Sep 17 00:00:00 2001 From: Matt Schiros Date: Fri, 18 Jan 2019 11:49:16 -0800 Subject: [PATCH] moving the check higher up in the if-blocks so it catches all the cases for both types --- model_struct.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/model_struct.go b/model_struct.go index 63ddede6..b33416d9 100644 --- a/model_struct.go +++ b/model_struct.go @@ -274,6 +274,11 @@ func (scope *Scope) GetModelStruct() *ModelStruct { elemType = elemType.Elem() } + if arbitraryConditions, _ := field.TagSettingsGet("ARBITRARY_JOIN_CONDITIONS"); arbitraryConditions != "" { + relationship.ArbitraryJoinConditions = strings.Split(arbitraryConditions, ",") + } + + if elemType.Kind() == reflect.Struct { if many2many, _ := field.TagSettingsGet("MANY2MANY"); many2many != "" { relationship.Kind = "many_to_many" @@ -342,10 +347,6 @@ func (scope *Scope) GetModelStruct() *ModelStruct { // 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.Setup(relationship, ToTableName(many2many), reflectType, elemType) 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 len(foreignKeys) == 0 { @@ -476,6 +474,10 @@ func (scope *Scope) GetModelStruct() *ModelStruct { polymorphicType.IsForeignKey = true } } + + if arbitraryConditions, _ := field.TagSettingsGet("ARBITRARY_JOIN_CONDITIONS"); arbitraryConditions != "" { + relationship.ArbitraryJoinConditions = strings.Split(arbitraryConditions, ",") + } // Has One {