From 087b7083ad1154ff0573d560b64310e4869a2820 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 25 Feb 2015 11:17:33 +0800 Subject: [PATCH] Fix scope Fields with embedded struct --- embedded_struct_test.go | 6 ++++++ model_struct.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/embedded_struct_test.go b/embedded_struct_test.go index 17405b74..74997f13 100644 --- a/embedded_struct_test.go +++ b/embedded_struct_test.go @@ -39,4 +39,10 @@ func TestSaveAndQueryEmbeddedStruct(t *testing.T) { if DB.NewScope(&HNPost{}).PrimaryKeyField() == nil { t.Errorf("primary key with embedded struct should works") } + + for _, field := range DB.NewScope(&HNPost{}).Fields() { + if field.Name == "BasePost" { + t.Errorf("scope Fields should not contain embedded struct") + } + } } diff --git a/model_struct.go b/model_struct.go index d64b93c7..ed299e85 100644 --- a/model_struct.go +++ b/model_struct.go @@ -237,7 +237,7 @@ func (scope *Scope) GetModelStruct(noRelationship ...bool) *ModelStruct { modelStruct.PrimaryKeyField = f } } - break + continue } else { belongsToForeignKey := foreignKey if belongsToForeignKey == "" {