title: How do I store keys in a datastore object using Go?
body: <p>I'm trying to put a *Key of a Location</p>
  
  <pre><code>type Location struct 
      City, State, Country string
  }
  </code></pre>
  
  <p>in a Band</p>
  
  <pre><code>type Band struct {
      Name string
      LocationId *datastore.Key
      Albums []Album
  }
  </code></pre>
  
  <p>When I first create a Location, add the key, then try to retrieve the Location values, the strings all come out empty. If I then add a new Band, the location I created shows up fine, and using that location in a new Band works. I'm using incomplete keys:</p>
  
  <pre><code>func AddLocation(value Location, rq *http.Request) (*datastore.Key, error) {
      c := appengine.NewContext(rq)
      key := datastore.NewIncompleteKey(c, config.LOCATION_TYPE, nil)
      _, err := datastore.Put(c, key, &amp;value)
  
      return key, err
  }
  </code></pre>
  
  <p>Using an existing Location is as follows:</p>
  
  <pre><code>case "existing":
      rawId := rq.FormValue("location_id")
      q := strings.Split(rawId, ",")
      x := q[1]
      id_int, e := strconv.ParseInt(x, 10, 64)
      if e != nil {
          message = e.Error()
      }
      locationId = datastore.NewKey(c, config.LOCATION_TYPE, "", id_int, nil)
      //  message = "not implemented yet"
      break
  </code></pre>
  
  <p>Using the key from the original Put didn't seem to work, so I resorted to:</p>
  
  <pre><code>case "new":
      location := model.Location{rq.FormValue("city"), rq.FormValue("state"), rq.FormValue("country")}
      var err error
      _, err = model.AddLocation(location, rq)
      if err != nil {
          message = "Location add: " + err.Error()
      }
      q := datastore.NewQuery(config.LOCATION_TYPE).Filter("City =", location.City).
          Filter("State =", location.State).Filter("Country =", location.Country).
          KeysOnly()
      keys, err := q.GetAll(c, nil)
      if err != nil {
      message = "Location add: " + err.Error()
      }
      var k *datastore.Key
      for _, key := range keys {
          k = key
          break
      }
      locationId = k
      break
  </code></pre>
  
  <p>And that didn't work right either. What am I not getting? </p>