我将实体(作为datastore.PropertyList)放入数据存储中,如下所示:
// save one
var plist datastore.PropertyList = make(datastore.PropertyList, 3)
plist = append(plist, datastore.Property { "name", "Mat", false, false })
plist = append(plist, datastore.Property { "age", "29", false, false })
plist = append(plist, datastore.Property { "location", "London", false, false })
key := datastore.NewIncompleteKey(context, "Record", nil)
datastore.Put(context, key, &plist)
// save another one
var plist datastore.PropertyList = make(datastore.PropertyList, 3)
plist = append(plist, datastore.Property { "name", "Laurie", false, false })
plist = append(plist, datastore.Property { "age", "27", false, false })
plist = append(plist, datastore.Property { "location", "London", false, false })
key := datastore.NewIncompleteKey(context, "Record", nil)
datastore.Put(context, key, &plist)
一切正常(尽管上面的代码现在更像是伪代码)。我能够分别加载它们,并且datastore.PropertyList每个字段都随其单独提供datastore.Property。
但是,当我尝试使用检索其中许多内容时Query,操作失败:
query := datastore.NewQuery("Record")
plists := make(datastore.PropertyList, 0, 10)
keys, err := query.GetAll(context, &plists)
我收到以下错误:
datastore: cannot load field "age" into a "datastore.Property": no such struct field
似乎并没有抱怨,Name因为那恰好是的有效属性datastore.Property,所以我如何获取它以按预期的方式加载项目,而每个项目plists都是datastore.PropertyList而不是datastore.Property?
人到中年有点甜
白衣染霜花
相关分类