GQL query for efficient entity communication

I'm in a situation where I need to encompass a Google App Engine entity relationship in a type query in a Django database model . I've been using ListProperty

for a relationship, "one to many", for example:

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

      

And I would like to execute a query that does the following:

# 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()]

      

Understanding seems radically ineffective. I would really like to execute a query like in the comments part, but it doesn't look like GQL syntax allows queries against 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>

      

0


source to share


1 answer


You are correct, App Engine datastore does not allow such a request. And you are correct that list comprehension is ineffective. Think, however, that this is pretty much what a relational database does when doing a query with joins like yours - the database should do the same O (n ^ 3) work you are doing here - the only difference is that you are doing it in Python and with extra round trip time. Since App Engine is designed to scale, it really isn't designed for such requests.



Usually, though, you can restrict your model a little to ease this by moving some of the properties you need to access the Foo model, or if you are doing aggregations by moving the total to the Foo model. It is difficult to give specific solutions, let alone what problem you are trying to solve.

+3


source







All Articles