At a bare minimum, you want to do something like this: results = session.query(Container).options(sqlalchemy.orm.____load('children')).all()
Where: * ____load is either "joinedload" or "subqueryload". "joinedload" issues 1 sql statement with the child table joined. "subqueryload" issues a second sql statement to load the children, based on the first statement. the performance of each varies based on the query. * 'children' is a defined orm relationship. Another trick you may be able to do is to pre-cache all the items: containers = session.query(Container).all() child_ids = [c.child_id for c in containers] children = session.query(Children).filter(Children.id.in_(child_ids)).all() IIRC, I think this will work in cases where there is a "*-to-one" relationship, because the target's primary key will be known to sqlalchemy's identity map. I could be wrong, but I think that will usually work. I use a caching layer to handle most of these things. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.