英文:
Update a datastore entity - change ancestor without changing entity key
问题
是否可以在不更改实体键的情况下更新实体的祖先?我该如何在Go中实现这一点?
我有一个类似于以下结构的层次结构:
公司/部门/员工
最初,员工没有分配到部门:公司/员工。
然后,当他/她被分配到一个部门时,我希望将其更改为:公司/部门/员工,但我希望实体键保持不变,因为它已经在其他地方用于引用此实体。
英文:
Is it possible to update the ancestor of an entity without changing the entity key? How would I accomplish that in Go?
I have a hierarchy similar to this:
Company/Department/Employee
It started off with no department for the employee: Company/Employee.
Then later when he/she gets assigned to a department, I want to change it to: Company/Department/Employee, but I want the entity key to remain the same as it is already used elsewhere to reference this entity.
答案1
得分: 3
不相信可以。祖先是键的一部分。
在Go中,你需要使用实体组吗?我尽量避免使用实体组,因为它们会增加太多限制。我建议你为Employee实体添加Company和Department属性:
type Employee struct {
Company, Department string
}
你仍然可以通过这些属性进行查询,尽管在更新后可能会有几秒钟的延迟。如果你需要强一致性,你可以通过键来查找Employee。这将始终返回最新版本。
英文:
> Is it possible to update the ancestor of an entity without changing the entity key?
I don't believe so. The ancestor is part of the key.
> How would I accomplish that in Go?
Do you need to use an Entity Group here? I try to avoid entity group whenever possible. They add too many restrictions. I would suggest that you add properties to your Employee entity for Company and Department:
type Employee struct {
Company, Department string
}
You can still query by these properties, although there maybe a few second delay after they are updated. If you need strong consistency you can always look the Employee up by Key. That will always return the most uptodate version.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论