So I have a struct like this
type Bus struct {
Number string
Name string
DirectStations []Station // Station is another struct
ReverseStations []Station
}
and I'm trying to store an instance of this to the Datastore:
key := datastore.NewKey(c, "Bus", bus.Number, 0, nil)
_, err := datastore.Put(c, key, &bus)
but I'm getting the error
datastore:
flattening nested structs leads to a slice of slices:
field "DirectStations"
How does one solve this?
Edit:
Turns out you can't have a slice of struct, where that struct contains other slices.
Just encode this struct into json (bytes) and store the json in the datastore
EDIT / UPDATE
http://play.golang.org/p/neAGgcAIZG
Another option for anyone that comes here is to just not store the slice of structures as a child in the datastore then just load them up separately when you're loading the obj
Something like:
Then when you want to load the parent, let's assume this code is in a service module and you've got a handy data module to actually pull stuff from the datastore (which you probably should)
Obviously you'll want error checking and all that, but this is kind of what you've got to do for complex nested structures.