Fix primary key in embedded struct

This commit is contained in:
Jinzhu 2015-02-25 10:56:05 +08:00
parent 1011865b91
commit 07af30c548
2 changed files with 7 additions and 0 deletions

View File

@ -35,4 +35,8 @@ func TestSaveAndQueryEmbeddedStruct(t *testing.T) {
} else if egNews.BasePost.Title != "engadget_news" {
t.Errorf("embedded struct's value should be scanned correctly")
}
if DB.NewScope(&HNPost{}).PrimaryKeyField() == nil {
t.Errorf("primary key with embedded struct should works")
}
}

View File

@ -233,6 +233,9 @@ func (scope *Scope) GetModelStruct(noRelationship ...bool) *ModelStruct {
f = f.clone()
f.Names = append([]string{fieldStruct.Name}, f.Names...)
modelStruct.StructFields = append(modelStruct.StructFields, f)
if f.IsPrimaryKey {
modelStruct.PrimaryKeyField = f
}
}
break
} else {