[Sqlalchemy-tickets] Issue #3546: Query object having multiple entities fails when trying to join (
Brought to you by:
zzzeek
|
From: Andrey S. <iss...@bi...> - 2015-10-02 11:32:46
|
New issue 3546: Query object having multiple entities fails when trying to join https://bitbucket.org/zzzeek/sqlalchemy/issues/3546/query-object-having-multiple-entities Andrey Semenov: ``` #!python Session.query(Address, Order, OrderLog).outerjoin(OrderLog, Order.id == OrderLog.order_id) ``` This code produces a query like: ``` #!SQL SELECT ... FROM orders, addresses LEFT OUTER JOIN order_logs ON orders.id = order_logs.order_id ``` This leads to an error at server side: ``` #!text ProgrammingError: (psycopg2.ProgrammingError) invalid reference to FROM-clause entry for table "orders" LINE 3: ...M orders, addresses LEFT OUTER JOIN order_logs ON orders.id ... ^ ``` so, the autowiring joins (auto-grouping them by entity relationship given at join_clauses) does not work. The docs don't say how to explicitly point the left part of join. The query I'm trying to build up is like: ``` #!SQL SELECT ... FROM entity_1 JOIN entity_1_1 ON ..., entity_2 JOIN entity_2_1 ON ..., entity_3, entity_4 JOIN entity_4_1 ON ... ``` Current query builder chains all .join() of Query objects to the first entity of the `_entities` list |