我处于这样的情况中,需要在查询中跨越 Google App Engine 实体关联,就像 Django 数据库模型中的关系跨度查找一样。我使用ListProperty
来表示一对多关系,像这样:
class Foo(db.Model): bars = db.ListProperty(db.Key)
class Bar(db.Model): eggs = db.ListProperty(db.Key)
我想执行一个查询,它可以做到以下的事情:
# Foo.filter( bars.eggs = , target_egg)
[foo
for egg in eggs if egg == target_egg
for eggs in bar.eggs
for bar in foo.bars
for foo in Foo.all()]
理解似乎极不高效。我真的希望执行如注释部分所示的查询,但看起来GQL语法不允许查询属性的属性:
SELECT * FROM <kind>
[WHERE <condition> [AND <condition> ...]]
[ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
[LIMIT [<offset>,]<count>]
[OFFSET <offset>]
<condition> := <property> {< | <= | > | >= | = | != } <value>
<condition> := <property> IN <list>
<condition> := ANCESTOR IS <entity or key>