GQL query to effectively span entity relationships
I'm in a situation where I need to span Google App Engine entity relationships in a query like [in the Django database model][1]. I'm using `ListProperty`s for one-to-many relationships, like so:

    class Foo(db.Model): bars = db.ListProperty(db.Key)
    class Bar(db.Model): eggs = db.ListProperty(db.Key)

And I'd like to perform a query that does the following:

    # Foo.filter('bars.eggs =', target_egg)
    [egg
    for egg in eggs if egg == target_egg
    for eggs in bar.eggs
    for bar in foo.bars
    for foo in Foo.all()]

The comprehension seems radically inefficient. I'd really like to perform a query as in the commented out portion, but it doesn't look like [the GQL syntax][2] allows for queries against the attributes of attributes:

       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>


  [1]: http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships
  [2]: http://code.google.com/appengine/docs/datastore/gqlreference.html
GQL query to effectively span entity relationships
===

I'm in a situation where I need to span Google App Engine entity relationships in a query like [in the Django database model][1]. I'm using `ListProperty`s for one-to-many relationships, like so:

    class Foo(db.Model): bars = db.ListProperty(db.Key)
    class Bar(db.Model): eggs = db.ListProperty(db.Key)

And I'd like to perform a query that does the following:

    # Foo.filter('bars.eggs =', target_egg)
    [egg
    for egg in eggs if egg == target_egg
    for eggs in bar.eggs
    for bar in foo.bars
    for foo in Foo.all()]

The comprehension seems radically inefficient. I'd really like to perform a query as in the commented out portion, but it doesn't look like [the GQL syntax][2] allows for queries against the attributes of attributes:

       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>


  [1]: http://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships
  [2]: http://code.google.com/appengine/docs/datastore/gqlreference.html