On Apr 18, 2008, at 3:18 PM, kris wrote:
> > select item.id > from item, > (select dataset_me.something_id > from (select * from base, dataset > where base.id = dataset.id and > base.owner="me") > as dataset_me > where > tag.c.name="good" and tag.c.parent_id == > dataset_me.id > ) as datasetsomething > where item.id = datasetsomthing.id > and tag.c.name="good" and tag.c.parent_id == item.id > If I add a simple "correlate" feature to Query in 0.5, you can use the raw Table object to bypass the ORM meaning of "Dataset" and "Base". the query above is not quite complete but I can get an approximation like this: subq = sess .query (dataset .c .id .label ('id ')).filter (Base .owner =='me').filter(dataset.c.id==Base.id).statement.alias('dataset_me') subq = sess .query (subq .c .id .label ('id ')).filter (Tag .name = = 'good ').filter (Tag .parent_id ==subq.c.id).correlate(Tag).statement.alias('datasetsomething') print sess .query (item .c .id ).filter (item .c .id = = subq .c .id).filter(Tag.name=='good').filter(Tag.parent_id==item.c.id).statement produces: SELECT item.id AS item_id FROM item, (SELECT dataset_me.id AS id FROM (SELECT dataset.id AS id FROM dataset, base WHERE base.owner = :owner_1 AND dataset.id = base.id) AS dataset_me WHERE tags.name = :name_1 AND tags.parent_id = dataset_me.id) AS datasetsomething, tags WHERE item.id = datasetsomething.id AND tags.name = :name_2 AND tags.parent_id = item.id So I think going forward, the concept of "use the Table objects directly" when you want to bypass the higher level meaning of "Dataset.id", i.e. that its selecting from a join of Dataset and Base, might be a good way to go with this. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---