[Sqlalchemy-tickets] Issue #3304: Add Query.get_all to query by list of IDs (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Marian S. <iss...@bi...> - 2015-02-06 15:29:23
|
New issue 3304: Add Query.get_all to query by list of IDs https://bitbucket.org/zzzeek/sqlalchemy/issue/3304/add-queryget_all-to-query-by-list-of-ids Marian Sigler: Inspiration for this: http://stackoverflow.com/a/21267811/196244 Sometimes one has a list of IDs and needs to fetch the associated objects. There's two ways to do that: session.query(Record).filter(Record.id.in_(seq)).all() map(session.query(Record).get, seq) Which one is better depends on whether most of the objects are already in the session or not. I assume it is trivial for SQLAlchemy to find out if this is the case, and choose the appropriate method. Thus I propose adding a method `Query.get_all` that takes a list of IDs and returns the corresponding objects, guessing the better method to use. (Bonus: to allow functions using it to either accept a list of ids or of objects, allow the objects as input, too) |