英文:
GAE filter entity key (Golang)
问题
我想使用类似的方式来获取实体键:
datastore.NewQuery("Article").Filter("ID =", id)
怎么做呢?
对不起,我的英语不好。谢谢!
英文:
I want to use look like
datastore.NewQuery("Article").Filter("ID =", id)
to get entity key.
How do this?
Sorry for my poor English. Thanks!
答案1
得分: 11
这些解决方案怎么样,这种方式不需要查询,也不需要迭代器,更直接地解决问题。
var article Article
k := datastore.NewKey(c, "Article", "", usrr.User, nil)
q := datastore.Get(c,k,&article)
你觉得怎么样?
英文:
What about these solution, these way you dont need a query, neither an iterator is more direct way of solving the problem.
var article Article
k := datastore.NewKey(c, "Article", "", usrr.User, nil)
q := datastore.Get(c,k,&article)
What did you think?
答案2
得分: 2
k := datastore.NewKey(c, "Activity", "", id, nil)
q := datastore.NewQuery("Article").Filter("key =", k)
其中 c
是你的 appengine.Context
英文:
I never tried Go but I'll give it a shot:
k := datastore.NewKey(c, "Activity", "", id, nil)
q := datastore.NewQuery("Article").Filter("__key__ =", k)
Where c
is your appengine.Context
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论