I have several tables derived from a base
base = Table ('base', ...,
Column ('id'), Integer, primarykey=True))
d1 = Table ('derived1',
Column ('id', Integer, ForignKey('base.id' ),
primarykey=True)
Column ('parent_id', Integer, ForignKey('base.id' ))
d2 = Table ('derived2',
Column ('id', Integer, ForignKey('base.id' ),
primarykey=True)
.Column ('parent_id', Integer,
ForignKey('base.id' ))
class B(object): pass
class D1(B):pass
class D2(B):pass
mapper (B, base)
mapper (D1, d1, inherits=Base)
mapper (D2, d2, inherits=Base)
I am building a tree structure of D1 and D2 nodes..
I am progressively generating a query as before execution using
subqueries.
s = session.query(D1).filter (...)._values(D1.c.id).statement
...
q = session.query (D2).select_from (s).filter (s.base_id ==
D2.parent_id)
print q
SELECT anon_1.base_id AS anon_1_base_id
FROM
(SELECT base.id AS base_id
FROM base JOIN derived1 ON base.id = derived1.id
WHERE ....) AS anon_1,
base, derived2
WHERE anon_1.base_id = derived2.parent_id ORDER BY anon_1.base_id
This seems to generating extra join expression with 'base' without
the filtering
the inheritance expression D2.c.id = Base.c.id
I tried adding the above expression to the filter directly:
q = session.query (D2).select_from (s).filter (and_(s.base_id ==
D2.parent_id,
B.c.id==D2.c.id)
but this produced
SELECT anon_1.base_id AS anon_1_base_id
FROM
(SELECT base.id AS base_id
FROM base JOIN derived1 ON base.id = derived1.id
WHERE ....) AS anon_1,
base, derived2
WHERE anon_1.taggable_id = derived2.parent_id AND anon_1.base_id =
anon_1.base_id ORDER BY anon_1.taggable_id
Any help appreciated.
Kris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---