Fix primary key in embedded struct
This commit is contained in:
parent
1011865b91
commit
07af30c548
@ -35,4 +35,8 @@ func TestSaveAndQueryEmbeddedStruct(t *testing.T) {
|
|||||||
} else if egNews.BasePost.Title != "engadget_news" {
|
} else if egNews.BasePost.Title != "engadget_news" {
|
||||||
t.Errorf("embedded struct's value should be scanned correctly")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,6 +233,9 @@ func (scope *Scope) GetModelStruct(noRelationship ...bool) *ModelStruct {
|
|||||||
f = f.clone()
|
f = f.clone()
|
||||||
f.Names = append([]string{fieldStruct.Name}, f.Names...)
|
f.Names = append([]string{fieldStruct.Name}, f.Names...)
|
||||||
modelStruct.StructFields = append(modelStruct.StructFields, f)
|
modelStruct.StructFields = append(modelStruct.StructFields, f)
|
||||||
|
if f.IsPrimaryKey {
|
||||||
|
modelStruct.PrimaryKeyField = f
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user