Created
November 15, 2012 15:34
-
-
Save doobeh/4079214 to your computer and use it in GitHub Desktop.
Subquery ORM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Get set of users who anthony sent a message to | |
| ## Isolate the user we care about. | |
| anthony = User.query.filter_by(username='anthony').first() | |
| ## What messages were sent by that user: | |
| subq = db.session.query(ChatHistory.with_user).filter(ChatHistory.user_id==anthony.id).distinct().subquery() | |
| ## What users does that relate to? | |
| users = User.query.filter(User.id.in_(subq)).all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment