From b6ff056b91834ec56f685c8735cd67c9b0603de7 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 20 Jan 2021 17:06:14 -0500 Subject: chain joins from SelectState context, not Select Fixed issue in new :meth:`_sql.Select.join` method where chaining from the current JOIN wasn't looking at the right state, causing an expression like "FROM a JOIN b , b JOIN c " rather than "FROM a JOIN b JOIN c ". Added :meth:`_sql.Select.outerjoin_from` method to complement :meth:`_sql.Select.join_from`. Fixes: #5858 Change-Id: I1346ebe0963bbd1e4bf868650e3ee1d6d3072f04 --- lib/sqlalchemy/sql/selectable.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/sql') diff --git a/lib/sqlalchemy/sql/selectable.py b/lib/sqlalchemy/sql/selectable.py index b4f6c8bc9..8e478583f 100644 --- a/lib/sqlalchemy/sql/selectable.py +++ b/lib/sqlalchemy/sql/selectable.py @@ -3944,7 +3944,7 @@ class SelectState(util.MemoizedSlots, CompileState): replace_from_obj_index = None - from_clauses = self.statement._from_obj + from_clauses = self.from_clauses if from_clauses: @@ -4644,6 +4644,19 @@ class Select( (target, onclause, None, {"isouter": isouter, "full": full}), ) + def outerjoin_from(self, from_, target, onclause=None, full=False): + r"""Create a SQL LEFT OUTER JOIN against this :class:`_expression.Select` + object's criterion + and apply generatively, returning the newly resulting + :class:`_expression.Select`. + + Usage is the same as that of :meth:`_selectable.Select.join_from`. + + """ + return self.join_from( + from_, target, onclause=onclause, isouter=True, full=full + ) + @_generative def join_from( self, from_, target, onclause=None, isouter=False, full=False -- cgit v1.2.1