I need something exactly like a SQL JOIN which cannot be done with appengine so I’m looking for a workaround. This is the query is want sorted by person.lastname
downline = User.query(User.sponsor == distributor.key).fetch()
for person in downline
orders = model.Order.all().filter('distributor_id =' , person.key.id()).filter('created >' , startdate).filter('status =', 'PAID').fetch(999999)
The query fetches the orders places by a person and basically I’ve got 2 kinds of entities, persons and orders. How should I go about to mimic that I join the persons (User) entity and sort the list by person’s lastname? This is a very easy thing to do in SQL and I couldn’t find a way to do it in appengine.
Can you tell me how I could add the person names in memory? The function doesn’t have to have very good performance since it is a reporting function.
You can connect your Person and Order models by parenting – a Person is the parent object of an Order. With that, it becomes simple to iterate over the Person set in order and select its orders.
Another way is to use a ListPoperty if you are using the current API or repeated properties if you are using NDB to link your Order’s to your Person’s.