I have the following entities:
class Book():
team = db.StringProperty()
class Entry():
role = db.StringProperty()
I create two Books:
book1 = Book(team='Plants').put()
book2 = Book(team='Zombies').put()
I create three Entrys:
entry1 = Entry(parent=book1, role='Peashooter').put()
entry2 = Entry(parent=book2, role='Gargantuar').put()
entry3 = Entry(parent=book2, role='Flag Zombie').put()
I can make a query for the 'Plants' Book:
query = Entry.all().ancestor(book1).fetch(100)
I’d like to make a query for several books. I can only think of list concatenation:
list1 = Entry.all().ancestor(book1).fetch(100)
list2 = Entry.all().ancestor(book2).fetch(100)
query = list1 + list2
Is there a more elegant way to do this other than list concatenation?
If you want to combine queries for several different ancestors (that don’t share a common ancestor), the only way to do it is with separate queries, as you demonstrate. This is no different than if you want to query for several distinct values in a field.