summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/dynamic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-11-12 15:09:37 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2018-11-13 18:36:24 -0500
commit40c1a46e993b5c5ff917ce41c3dca66c139bde94 (patch)
tree63d2dfda930fdb549f6edf062c1101dd5998097c /lib/sqlalchemy/orm/dynamic.py
parenta698bdbc5716201804ddedde6a0fc5ab33d43300 (diff)
downloadsqlalchemy-40c1a46e993b5c5ff917ce41c3dca66c139bde94.tar.gz
Insert primary entity in dynamic "secondary"
Fixed regression caused by :ticket:`4349` where adding the "secondary" table to the FROM clause for a dynamic loader would affect the ability of the :class:`.Query` to make a subsequent join to another entity. The fix adds the primary entity as the first element of the FROM list since :meth:`.Query.join` wants to jump from that. Version 1.3 will have a more comprehensive solution to this problem as well (:ticket:`4365`). Fixes: #4363 Change-Id: I1abbb6207722619dc5369e1fd96de43d60a1ee62
Diffstat (limited to 'lib/sqlalchemy/orm/dynamic.py')
-rw-r--r--lib/sqlalchemy/orm/dynamic.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/dynamic.py b/lib/sqlalchemy/orm/dynamic.py
index 3c59f61d7..087e7dcc6 100644
--- a/lib/sqlalchemy/orm/dynamic.py
+++ b/lib/sqlalchemy/orm/dynamic.py
@@ -221,7 +221,13 @@ class AppenderMixin(object):
prop = mapper._props[self.attr.key]
if prop.secondary is not None:
- self._set_select_from([prop.secondary], False)
+ # this is a hack right now. The Query only knows how to
+ # make subsequent joins() without a given left-hand side
+ # from self._from_obj[0]. We need to ensure prop.secondary
+ # is in the FROM. So we purposly put the mapper selectable
+ # in _from_obj[0] to ensure a user-defined join() later on
+ # doesn't fail, and secondary is then in _from_obj[1].
+ self._from_obj = (prop.mapper.selectable, prop.secondary)
self._criterion = prop._with_parent(
instance,