英文:
datastore.Get using a grandparent key
问题
有没有一种方法可以通过提供实体的根父级而不是完整路径来执行datastore.Get
操作?
例如,假设有一个SubFolder
实体,在一个Folder
实体下,而该Folder
实体本身又在一个User
实体下。下面的代码是无效的:
subFolderKey := datastore.NewKey(c, "SubFolder", "mySubfolder", 0, userKey)
datastore.Get(c, subFolderKey, subFolder)
即使mySubfolder
是userKey
的孙子。
有没有一种方法可以在不指定完整父路径的情况下实现这一点?
英文:
Is there some way to perform a datastore.Get
by providing not the full path of the key, but, say, the root parent of an entity?
For instance, say there's a SubFolder
entity, under a Folder
entity which itself is under a User
entity. This doesn't work:
subFolderKey := datastore.NewKey(c, "SubFolder", "mySubfolder", 0, userKey)
datastore.Get(c, subFolderKey, subFolder)
even though mySubfolder
is a grandchild of userKey
.
Is there some way to do this without specifying full parent path?
答案1
得分: 1
不,这是不可能的。祖先路径是实体的完整键,如果你遗漏了某些内容,那么你将得到一个不完整的键。
英文:
No, that is not possible. The ancestor path is the full key of your entity so if you leave something out, you will have an incomplete key.
See also this SO answer.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论