Moved from GitHub dgo/6
Posted by nikkon226:
When I try to update, the update does not add the uid to the api.Assigned map, but does update the database.
// type model {
// UID string `json:"uid,omitempty"`
// Name string `json:"name,omitempty"`
// }
input := &model{
UID: "0x1234",
Name: "Test",
}
inputJson, err := json.Marshal(input)
if err != nil {
log.Println("error handing json marshal")
return nil
}
mu := &api.Mutation{
SetJson: inputJson,
CommitNow: true,
}
log.Println("mutation object:", mu)
// mutation object: set_json:"{\"uid\":\"0x1234\",\"name\":\"Test\"}" commit_now:true
txn := o.graph.NewTxn()
defer txn.Discard(ctx)
assigned, err := txn.Mutate(ctx, mu)
if err != nil {
log.Println("error handing mutation for update")
return nil
}
log.Println("assigned:", assigned.Uids)
// assigned: map[]
// the database has changed the name to "Test"
if _, ok := assigned.GetUids()[input.ID]; !ok {
log.Println("update unsuccessful")
return nil
}