From fdfd1680603f6663182ba4766ae2f5abdd3ced45 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 14 Nov 2018 11:02:40 -0500 Subject: Add secondary selectable to FROM clauses for correlated exists In continuing with a similar theme as that of very recent :ticket:`4349`, repaired issue with :meth:`.RelationshipProperty.Comparator.any` and :meth:`.RelationshipProperty.Comparator.has` where the "secondary" selectable needs to be explicitly part of the FROM clause in the EXISTS subquery to suit the case where this "secondary" is a :class:`.Join` object. Fixes: #4366 Change-Id: Icd0d0c3871bbd0059f0c9256e2b980edc2c90551 --- lib/sqlalchemy/orm/relationships.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index adcaa5927..e7896c423 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -1110,9 +1110,12 @@ class RelationshipProperty(StrategizedProperty): crit = j & sql.True_._ifnone(criterion) - ex = sql.exists([1], crit, from_obj=dest).correlate_except(dest) if secondary is not None: - ex = ex.correlate_except(secondary) + ex = sql.exists([1], crit, from_obj=[dest, secondary]).\ + correlate_except(dest, secondary) + else: + ex = sql.exists([1], crit, from_obj=dest).\ + correlate_except(dest) return ex def any(self, criterion=None, **kwargs): -- cgit v1.2.1