[Sqlalchemy-tickets] Issue #3348: loader options from non_primary mappers (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-03-31 17:09:48
|
New issue 3348: loader options from non_primary mappers https://bitbucket.org/zzzeek/sqlalchemy/issue/3348/loader-options-from-non_primary-mappers Mike Bayer: e.g. query.options(joinedload_all("a.bs_np.c")), where "bs_np" refers to a non primary mapper. can't use getattr() here: ``` #!diff diff --git a/lib/sqlalchemy/orm/strategy_options.py b/lib/sqlalchemy/orm/strategy_options.py index cb7a5fe..70f4caa 100644 --- a/lib/sqlalchemy/orm/strategy_options.py +++ b/lib/sqlalchemy/orm/strategy_options.py @@ -128,21 +128,24 @@ class Load(Generative, MapperOption): attr = "%s:%s" % (wildcard_key, attr) return path.token(attr) - try: - # use getattr on the class to work around - # synonyms, hybrids, etc. - attr = getattr(path.entity.class_, attr) - except AttributeError: - if raiseerr: - raise sa_exc.ArgumentError( - "Can't find property named '%s' on the " - "mapped entity %s in this Query. " % ( - attr, path.entity) - ) - else: - return None + if path.entity.non_primary: + attr = path.entity._props[attr] else: - attr = attr.property + try: + # use getattr on the class to work around + # synonyms, hybrids, etc. + attr = getattr(path.entity.class_, attr) + except AttributeError: + if raiseerr: + raise sa_exc.ArgumentError( + "Can't find property named '%s' on the " + "mapped entity %s in this Query. " % ( + attr, path.entity) + ) + else: + return None + else: + attr = attr.property path = path[attr] else: ``` this might apply to 0.9 as well. |