duanlan7239 2018-10-01 07:49
浏览 13
已采纳

如何在数据存储区中定义密钥类型?

I have a user kind:

type User struct {
  Username     string
  Email        string
  Password     string
}

And a post kind:

type Post struct {
  User               // how to define here?
  Title        string
  Content      string
}

Post entity looks like:

User: Key(User, '10000')

Title: "some tilte"

Content: "some content"

How can define Post.User?

  • 写回答

1条回答 默认 最新

  • doupo1890 2018-10-01 07:56
    关注

    Since your Post entities contain complete Keys, use datastore.Key as the field type:

    type Post struct {
        User    *datastore.Key
        Title   string
        Content string
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?