我的情况是,我需要在 Django 数据库模型中的查询中跨越 Google App Engine 实体关系。我将ListProperty
s 用于一对多关系,如下所示:
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>