How would I implement one-to-many on Google App Engine in the Go programming language?
For example, if I have the structs below, how would I store the association of many Votes to one Comment? Would I use an array (slice) of keys to Votes in the Comment struct, or one key to the Comment from the Vote struct?
type Comment struct {
Author string
Content string
Date datastore.Time
}
type Vote struct {
User string
Score int
}
The only types that are allowed for fields in the current version of the Go AppEngine SDK are as follows:
Given that, there appear to be two ways to do this. One is to maintain a slice of keys to point to the Votes of a given Comment. However this is likely to run up against the 100 element limit for any reasonably popular comment.
The other approach is to store a “pointer” to the comment in each vote struct like this:
Then when you go to query it you need to do it in two steps. First you get the Comment you’re interested in (in this case just the first one that happens to be returned). Second, you query for all the votes that “point” to that comment: