datastore.Get 使用祖父键

huangapple go评论80阅读模式
英文:

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)

即使mySubfolderuserKey的孙子。

有没有一种方法可以在不指定完整父路径的情况下实现这一点?

英文:

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

不,这是不可能的。祖先路径是实体的完整键,如果你遗漏了某些内容,那么你将得到一个不完整的键。

参见这个 Stack Overflow 回答

英文:

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.

huangapple
  • 本文由 发表于 2013年8月27日 07:00:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/18454398.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定