From 483a644959f396e3abdcb8f0f373936569958970 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 27 Apr 2020 16:51:43 -0400 Subject: Alias the onclause if ORM join is to same polymorphic selectable Fixed bug where using :func:`.with_polymorphic` as the target of a join via :meth:`.RelationshipComparator.of_type` on a mapper that already has a subquery-based with_polymorphic setting that's equivalent to the one requested would not correctly alias the ON clause in the join. Fixes: #5288 Change-Id: I0212a990ee67a344c87fe21833bf47fdb72ca0cc --- lib/sqlalchemy/orm/relationships.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/orm/relationships.py') diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 6ac56a324..85f23d159 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -2377,7 +2377,10 @@ class RelationshipProperty(StrategizedProperty): if self._is_self_referential and source_selectable is None: dest_selectable = dest_selectable._anonymous_fromclause() aliased = True - elif dest_selectable is not self.mapper._with_polymorphic_selectable: + elif ( + dest_selectable is not self.mapper._with_polymorphic_selectable + or self.mapper.with_polymorphic + ): aliased = True dest_mapper = of_type_mapper or self.mapper -- cgit v1.2.1