I am currently in the process on deciding which stack I'll use for a (small) social network . I would love to code it in golang on top of Google App Engine since this would result in clean, fast code with all the advantages of modern cloud services & hosting.
How would you implement one-to-many and/or many-to-one relationships in GAE with golang? According to the docs you can use your own types in datastore-structs, as long as their properties are the ones mentioned in the documentation. So for example:
type Comment struct {
Title string
Text string
User *User
}
type Photo struct {
Description string
Comments []*Comment
}
should work in my opinion, am I right? And if I am right, how can I:
a) populate this relationship in one query?
b) add comments to a photo in a convenient way? (such as MongoDBs '$push')
best, Michel
On App Engine, you can model this with two entity types:
type Comment struct {
Title string
Text string
User *User
}
type Photo struct {
Description string
}
Use an ancestor path to associate child comments with a parent photo. You can get all comments for a photo in a single query. You can add comments by putting new comment entities.
I think you can store a photo using the types in the question (it looks like you can according to the doc, but I have no personal experience with nesting three levels in an entity). To add a comment with this design, the application fetches the photo (this will include the comments), adds the comment to the photo, and puts the photo with all comments back to the datastore.
App Engine does not have entity modification operators like Mongo's $push.