hi. i have the case of polymorphic mapper referencing itself (or other of it's sub-class objects), and i want to query/filter on a value of the referenced object. e.g. all people who have friends of age > 25.
if i use direct the leafs of the hierarchy, that works:
#case 1
t1 = table_human.alias()
q = session.query( VIPerson).select(
(table_human.c.friend_id==t1.c.db_id) & (t1.c.age > 25) )
but i need it off the root, e.g. something like
#case 2:
pu = mapper_Human.select_table #the polymorphic union itself
other = pu.alias()
q = session.query( Human).select(
(pu.c.friend_id == other.c.db_id) & (other.c.age > 25) )
and it doesn't work.
i've tried simpler case, against the table (not the union), and it
doesn't work either:
#case 3
other = table_human.alias()
q = session.query( Human).select(
(mapper_Human.select_table.c.friend_id == other.c.db_id)
& (other.c.age > 25) )
it seems to miss a second entry in FROM; and all columns in the
whereclause have become belonging to the union.
e.g.
SELECT pu_human.db_id AS pu_human_db_id, pu_human.name AS
pu_human_name, pu_human.friend_id AS pu_human_friend_id, pu_human.age
AS pu_human_age, pu_human.atype AS pu_human_atype, pu_human.alias AS
pu_human_alias
FROM (
SELECT person.db_id AS db_id, human.name AS name, human.friend_id AS
friend_id, human.age AS age, human.atype AS atype, person.alias AS
alias
FROM human JOIN person ON person.db_id = human.db_id
UNION ALL
SELECT bz4human.db_id AS db_id, bz4human.name AS name,
bz4human.friend_id AS friend_id, bz4human.age AS age, bz4human.atype
AS atype, CAST(NULL AS TEXT) AS alias
FROM (
SELECT human.age AS age, human.name AS name, human.friend_id AS
friend_id, human.db_id AS db_id, human.atype AS atype
FROM human
WHERE human.atype = ?
) AS bz4human
) AS pu_human
WHERE pu_human.friend_id = pu_human.db_id AND pu_human.age > ? ORDER
BY pu_human.oid
any idea?
svil
btw. in the polymorphic_union(), is that forced aliasing on any
select() entries really needed?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
aaa.py
Description: application/python
