Google app engine 使用Go和数据存储查询数组

Google app engine 使用Go和数据存储查询数组,google-app-engine,go,google-cloud-datastore,Google App Engine,Go,Google Cloud Datastore,我有以下情况: type Band struct { Name string LocationId *datastore.Key Albums []Album } type Album struct { Name string GenreId *datastore.Key Year int } 我想做的是查询乐队s相册键,查找具有特定GenreId键的相册。我找到了答案。结果很简单。而不是 Filter("Gen

我有以下情况:

type Band struct {
    Name       string
    LocationId *datastore.Key
    Albums     []Album
}

type Album struct {
    Name    string
    GenreId *datastore.Key
    Year    int
}

我想做的是查询
乐队
s
相册
键,查找具有特定
GenreId
键的相册。

我找到了答案。结果很简单。而不是

Filter("GenreId =", genreId)
我曾经

Filter("Albums.GenreId =", genreId)

这为我提供了有效的查询结果。

通常过滤器工作时不需要指定“实体种类”,您可能需要检查config.BAND_TYPE是否为空,这可能导致查询作为“kindless查询”(针对所有种类的查询)运行。BAND_TYPE的定义如下:const BAND_TYPE=“BAND”在dataconfig.goi中,如果您阅读顶部的我的代码,您将看到GenreId存储在相册数组中。