<snip> > > what I notice about both of these are that you're using correlations. > So right off , using the Query, which has opinions about how to build > select statements, to build up a statement like this with its current > functionality (as well as what we're planning to do in 0.5) is awkward > if not impossible. The Query thinks in terms of "entities", such as > "Dataset" or "Item" - when it sees that one of those is desired, it's > going to use the full selectable for each of those entities, such as > "dataset join base" or "item join base" for example. The Query is > meant for when you want to think more in terms of objects and not > about statement optimization, nor the specifics of joining together > the individual tables used to load an inheriting class. The > "from_self()" use case, which is essentially what you're playing with, > is a new feature we have which provides a way to "select from the > results of a query", but is still not as flexible as raw select() > constructs.
I can't seem to find many references to "from_self()". It seems like the code comes quite close to what we need, however, as I mentioned in my first email, it gets mixed up by the base class. I'm looking for a way to disambiguate the call or add an extra filter to disambiguate. > To build up a select() statement at a fine grained level like this is > more appropriate using the select() construct directly. You can then > feed this construct into the Query using query.from_statement() which > will load a distinct entity from each row (or alternatively you can > configure it to load multiple entities horizontally from each row). o I would do something like the following? d = select([dataset,base], and_(base.c.id == dataset.id, base.c.owner="me")) d = d.where (and_(tag.c.name=="good", tag.c.parent_id ==base.c.id)) i = select([item]).join(d.alias('d')).where (item.id == d.c.id) i = i.where (and_(tag.c.name =="really", tag.c.parent_id == item.c.id)) session.query(Item).from_statement(i) BTW here's another example of something similar I have a graph of nodes with relationship on the edges nodes = Table ('node', Column ('id', ...) Column ('name', Text assoc = Table ('assoc', Column ('node1_id', Integer , Foriegn('node.id') Column ('node2_id', Integer , Foriegn('node.id') Column ('relation', Text) mapper (Node, nodes) ... I want to find all alias nodes for the components associated with node 100 n (100) -> hasa (n) -> isa () I know I could do this a multiple join, but due to the size of the node table I really want to avoid joins.. Also none of expressions should be correlated. select * from nodes, (select node2_id as id2 from assoc, (select node2_id as id1 from assoc where relation = 'is-a' and node1_id = 100) as isa where relation = 'has-a' and node1_id = isa.id ) as hasa where nodes.id = hasa.id2 Is there any way to generate this using the ORM level? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---