I want to have the following query in sqlalchemy:

SELECT t_objects_1.tid AS t_objects_1_tid FROM t_objects AS
t_objects_2 INNER JOIN c_objects AS c_objects_1 ON t_objects_2.tid =
c_objects_1.tid INNER JOIN t_objects AS t_objects_1 ON t_objects_1.tid
= t_objects_2.parent_id WHERE c.id = 1;

this would return a list of parent_ids whose childs match a certain
condition...


I would go like the following:
s.query(t_objects_1.tid).join((c_objects, t_objects_2.tid ==
c_objects.tid),(t_objects_1, t_objects_1.tid ==
t_objects_2.parent_id)).filter(c_objects.id == 1).all()


...but I get this error: (OperationalError) (1066, "Not unique table/
alias: 't_objects_1'")

so sqlalchemy is putting the wrong alias in the from clause:

SELECT t_objects_1.tid AS t_objects_1_tid FROM t_objects AS
t_objects_1 INNER JOIN c_objects AS c_objects_1 ON t_objects_2.tid =
c_objects_1.tid INNER JOIN t_objects AS t_objects_1 ON t_objects_1.tid
= t_objects_2.parent_id WHERE c.id = %s'

how can I bring sqlalchemy to use 't_objects_2' instead of
't_objects_1'?


Due to project constraints I have to use sqlalchemy==0.5.6

if maybe this is a known bug of 0.5.6 please let me now

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to