使用Go和Datastore查询数组

huangapple go评论83阅读模式
英文:

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
}

我想要做的是查询一个 BandAlbums 键,找到具有特定 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 Bands 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.

huangapple
  • 本文由 发表于 2014年5月8日 22:30:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/23544796.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定