I have the following mapper:
orm.mapper(Xxx,xxx_table, inherits=Resource,
polymorphic_identity=u'xxx',
properties={'children' : orm.relation(Xxx,
backref=orm.backref('parent', remote_side=[Xxx.c.id]),
primaryjoin=xxx_table.c.rid==xxx_table.c.parent_id)})
When I issue the following join, I get as the selected entity the parent
side rather than the child side of the join.
query = sqlalchemy.orm.query(Xxx)
query = query.join('parent', aliased=True)
query = query.filter(<some criterion>)
The SQL that is generated is as follows:
SELECT anon_1.resource_id AS anon_1_resource_id
FROM resource INNER JOIN xxx ON resource.id = xxx.id INNER JOIN (SELECT
resource.id AS resource_id
FROM resource INNER JOIN xxx ON resource.id =
xxx.id) AS anon_1 ON anon_1.xxx_id = xxx.parent_id
WHERE anon_1.resource_name .....
What I really want is
SELECT resource_id AS resource_id
FROM resource INNER JOIN xxx ON resource.id = xxx.id INNER JOIN (SELECT
resource.id AS resource_id
FROM resource INNER JOIN xxx ON resource.id =
xxx.id) AS anon_1 ON anon_1.xxx_id = xxx.parent_id
WHERE anon_1.resource_name .....
Any help is appreciated.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/Lm2ZI32QbvEJ.
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.