Re: [Sqlalchemy-tickets] [sqlalchemy] #2587: flatten joined-inheritance join targets on individual
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-05-31 19:28:35
|
#2587: flatten joined-inheritance join targets on individual tables
------------------------------+---------------------------------------
Reporter: zzzeek | Owner: zzzeek
Type: enhancement | Status: new
Priority: medium | Milestone: 0.9.0
Component: orm | Severity: very major - up to 2 days
Resolution: | Keywords:
Progress State: in queue |
------------------------------+---------------------------------------
Comment (by zzzeek):
also:
when we join from A to a mapper "B join C" and we are aliasing, as in
eager loading:
{{{
orm_join(A, BC.alias())
SELECT a.id AS a_id, anon_1.b_id AS anon_1_b_id, anon_1.c_id AS
anon_1_c_id
FROM a JOIN (
SELECT b.id AS b_id, c.id AS c_id FROM
b JOIN c ON b.id=c.id
) AS anon_1 ON a.id=anon_1.b_id
}}}
we can do the "flattened" thing, where we don't create the subquery, but
again produce the same labels:
{{{
orm_join(A, BC.unnessted_alias())
SELECT a.id AS a_id, anon_1_b.id AS anon_1_b_id, anon_1_c.id AS
anon_1_c_id
FROM a JOIN (b AS anon_1_b JOIN c AS anon_1_c ON anon_1_b.id=anon_1_c.id)
ON a.id=anon_1_b_id
}}}
again, we get the same labeling conventions and everything, we here just
change how `Alias` represents its contents. Perhaps `JoinedAlias`
subclass.
The above query, when run through the previous compiler "subquery the
nested joins" converter, gets:
{{{
SELECT a.id AS a_id, anon_2.anon_1_b_id AS anon_1_b_id, anon_2.anon_1_c_id
AS anon_1_c_id
FROM a JOIN (
SELECT anon_1_b.id AS anon_1_b_id, anon_1_c.id AS anon_1_c_id
FROM b AS anon_1_b JOIN c AS anon_1_c ON anon_1_b.id=anon_1_c.id
) AS anon_2
ON a.id=anon_2.anon_1_b_id
}}}
and it works
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2587#comment:4>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|