From d61b7db8fa089af8cf33198522fa92fb236de3d1 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 11 Aug 2017 18:03:32 +0800 Subject: [PATCH] Fix postgres tests --- model_struct.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/model_struct.go b/model_struct.go index 9c7c1a15..315028c4 100644 --- a/model_struct.go +++ b/model_struct.go @@ -97,7 +97,11 @@ func (structField *StructField) clone() *StructField { TagSettings: map[string]string{}, Struct: structField.Struct, IsForeignKey: structField.IsForeignKey, - Relationship: structField.Relationship, + } + + if structField.Relationship != nil { + relationship := *structField.Relationship + clone.Relationship = &relationship } for key, value := range structField.TagSettings { @@ -222,7 +226,9 @@ func (scope *Scope) GetModelStruct() *ModelStruct { if subField.Relationship != nil && subField.Relationship.JoinTableHandler != nil { if joinTableHandler, ok := subField.Relationship.JoinTableHandler.(*JoinTableHandler); ok { - joinTableHandler.Setup(subField.Relationship, joinTableHandler.TableName, reflectType, joinTableHandler.Destination.ModelType) + newJoinTableHandler := &JoinTableHandler{} + newJoinTableHandler.Setup(subField.Relationship, joinTableHandler.TableName, reflectType, joinTableHandler.Destination.ModelType) + subField.Relationship.JoinTableHandler = newJoinTableHandler } }