On Nov 24, 2011, at 3:48 AM, Ronan Dunklau wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hello. > > Let's say I have users, and groups of users, related by a many-to-one > relationship. > > My data looks like this: > > Group1 > User1 - Male > User2 - Female > Group2 > User3 - Male > User4 - Male > > I can query the groups, eager-loading their users to avoid the > additionial queries, and iterate over the groups to dump the user list. > > Now, how can I keep the same data organisation (groups containing many > users), but filtering users by a random criteria ? > > I'd like to write a query returning the following results: > > Group1 > User1 - Male > Group2 > User3 - Male > User4 - Male > > > The solution we're using for now is to fetch a tuple of Group, User > and then to use python itertools.groupby function to build a tree of > group and users, but I'm sure sqlalchemy can provide us a more elegant > solution.
the contains_eager() usage pattern provides for the case where you want to "customize" the eager loading of collections or scalars: http://www.sqlalchemy.org/docs/orm/loading.html#routing-explicit-joins-statements-into-eagerly-loaded-collections > > - -- > Ronan Dunklau > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.18 (GNU/Linux) > > iQEcBAEBAgAGBQJOzgS8AAoJECTYLCgFy323mVQH/19akIU4bLXeXE41ulR5obV6 > MVk9rOQZYujHcys4kq99xHKP1EBXTtQ9fDVYBVnwVq8bc+50DOxmMaP0qtE+Rdtt > l9z1kkfmjrK+v3eIt3hUT+US4z9HV4ySshPj2uvKwxLjRLyJLKfht9J38ShWnDHr > l0ABOFXTtKKhQBtNh4NlbpReXWlnSju2rCTyhtFEHVd+wIxk0fqBmTPTVupiLjOz > dAz4Ce12ER0Bqbh8WuzV11TCfRnprBKe+80TtOzedYDr9oji2xFgUA1TB2m3GRCB > sOEY9m4S4FRX1OCuHNc8y91IQrVLJePn+i1CAjeSm2erkBNxFIXPzwaLDyz3GCc= > =uyjn > -----END PGP SIGNATURE----- > > -- > 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. > -- 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.