[Sqlalchemy-tickets] Issue #4316: Improvement to query.get in the case of multiple primary keys (zz
Brought to you by:
zzzeek
From: Alex R. <iss...@bi...> - 2018-08-07 17:43:14
|
New issue 4316: Improvement to query.get in the case of multiple primary keys https://bitbucket.org/zzzeek/sqlalchemy/issues/4316/improvement-to-queryget-in-the-case-of Alex Rothberg: Right now the `ident` parameter to `query.get` is a tuple in the case of composite primary keys with the stipulation: >For a composite primary key, the order of identifiers corresponds in most cases to that of the mapped :class:`.Table` object's primary key columns. Having to know and hard code the order of the primary keys seems less than ideal. I suggest accepting a dict mapping names to the values for the primary keys. My implementation of this looks like: ```python from sqlalchemy.inspection import inspect def get_by_pks(model, **kwargs): return model.query.get( tuple( kwargs[key.name] for key in inspect(model).primary_key ) ) ``` |