On Oct 9, 10:20 am, Wayne Witzel <[EMAIL PROTECTED]> wrote: > I have the following code: > > tags = [u"tag1", u"tag2"] > tag_count = len(tags) > > inner_q = select([shiptag_table.c.shipid]) > inner_w = inner_q.where( > and_(shiptag_table.c.tagid == Tag.id,Tag.name.in_(tags)) > > ).group_by(shiptag_table.c.shipid).having(func.count(shiptag_table.c.shipid ) > == tag_count) > > outer_q = select([Tag.id, Tag.name, > func.count(shiptag_table.c.shipid)]) > outer_w = outer_q.where( > and_(shiptag_table.c.shipid.in_(inner_w), > not_(Tag.name.in_(tags)), > Tag.id == shiptag_table.c.tagid) > ).group_by(shiptag_table.c.tagid) > > related_tags = meta.Session.execute(outer_w).fetchall() > return related_tags > > If I try to execute as is, I get the following error: > InvalidRequestError: Select statement 'SELECT shiptag.shipid > FROM shiptag, tag > WHERE shiptag.tagid = tag.id AND tag.name IN (:name_1) GROUP BY > shiptag.shipid > HAVING count(shiptag.shipid) = :count_1' returned no FROM clauses due > to auto-correlation; specify c > orrelate(<tables>) to control correlation manually. > >
Well I can laugh at myself. Re-read the docs and it was layed out for me right there. Added .correlate(None) to my inner_w and all is well. Thanks, Wayne --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---