英文:
Querying an array using Go and Datastore
问题
我有以下情景:
type Band struct {
Name string
LocationId *datastore.Key
Albums []Album
}
type Album struct {
Name string
GenreId *datastore.Key
Year int
}
我想要做的是查询一个 Band
的 Albums
键,找到具有特定 GenreId
键的专辑。
英文:
I have the following scenario:
type Band struct {
Name string
LocationId *datastore.Key
Albums []Album
}
type Album struct {
Name string
GenreId *datastore.Key
Year int
}
What I want to do is query a Band
s Albums
key for an album with a specific GenreId
key.
答案1
得分: 3
我找到了答案。原来很简单。我使用了以下代码替代:
Filter("GenreId =", genreId)
我使用了以下代码:
Filter("Albums.GenreId =", genreId)
这样就可以得到有效的查询结果。
英文:
I found the answer. It turned out to be simple. Instead of
Filter("GenreId =", genreId)
I used
Filter("Albums.GenreId =", genreId)
That gave me valid query results.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论