Hi all, I have two models: User and Project. The relationship is one-to-many. What I want to achieve is querying users and the number of projects they are connected to. I also want to order the users according to the project counts.
The following code seems to work, but the result is a list of (User, long) tuple. users = Session.query(User).select_from( outerjoin(User, Project, Project.user_id == User.id)) \ .add_column("count(projects.id)") \ .group_by(User.id) \ .order_by("count(projects.id) desc") \ .all() I want to access the project count as an attribute of user object. So the result will be just list of User objects, not a 2-tuple. I searched the documentation with keywords like "dynamic attributes" or "adding extra attributes to model" but unfortunately, I did not find a way. Is it a doable? Haldun. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@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 -~----------~----~----~----~------~----~------~--~---