I'm trying to make the below logic into 1 query, so I don't have to
run an individual query for each item; but can't figure out how to do
it in sqlalchemy.  Any ideas what the code would look like?

results = []

items = session.query(Item).filter(Item.type == "person")

for item in items
  annotations = session.query(Annotation)
        .filter(Annotation.item_id == item.id)
        .order_by(Annotation.creation_datetime.desc())

  annotationResult = None

  for annotation in annotations:
     if annotation.type == "x" or annotation.type == "y"
        annotationResult = annotation
        break;
  if annoationResult == None
        annotationResult = annotations[0]

  results.append(annotationResult)

return results

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to