【问题标题】:How to know existing children of an entity in Google App Engine (python)?如何知道 Google App Engine(python)中实体的现有子项?
【发布时间】:2012-05-17 06:29:46
【问题描述】:

我在父子关系中创建了实体:

# Create Employee entity
employee = Employee()
employee.put()

# Set Employee as Address entity's parent directly...
address = Address(parent=employee)

# ...or using its key
e_key = employee.key()
address = Address(parent=e_key)

# Save Address entity to datastore
address.put()

那么,假设我们只知道地址实体,想要获取父(员工)。 我们可以得到地址'父:

address.key().parent()

但是,当我只知道员工时,我不知道如何获取员工的孩子。我发现 Key.from_path(...) 方法是从父子关系中获取 Key 的,但我不知道如何处理。

【问题讨论】:

  • 目前我认为不可能从父母那里查询孩子。
  • 我确实在你的问题中看到了 Python,如果你可以实现类似的东西,我仍然将此链接粘贴到 Java 中的类似内容:stackoverflow.com/questions/528650/…

标签: google-app-engine


【解决方案1】:

您可以使用.ancestor() 查询过滤器查询(直接或间接)子级,如下所示:

  addresses = Address.all().ancestor(emp).fetch()

【讨论】:

  • 它比仅仅将父母的 id 存储在孩子的列中并通过该列与 id 的相等性来获取更快吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-20
  • 1970-01-01
  • 1970-01-01
  • 2011-01-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多