the sophisticated column correlation you're looking for will only work if you use query.select_from(s), in which case there's no point in creating the final subquery, just call select_from(j) to prevent an unnecessary layer of nesting. It also seems like your ultimate query is better expressed just as a join of three tables instead of a join to a subquery.
Otherwise, to use from_statement() you'd have to construct your select statement such that the names of all columns match exactly what the query would look for normally - i.e. "outside_id" for "test_table_id" since you're aliasing on "outside", etc. from_statement() is a more brute force approach in that way. On Apr 16, 2009, at 3:30 PM, dykang wrote: > > oh, haha, sorry. i've been staring at this too long. > > the real error (the one that I do get when I fix the example) is > > sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for > column 'inside.id'" > > they looked very similar, and i didn't look close enough. sorry > > On Apr 16, 12:27 pm, Michael Bayer <[email protected]> wrote: >> the error youre showing me, which is >> "sqlalchemy.exc.OperationalError: >> (OperationalError) (1054, "Unknown column 'inside.foo' in 'on >> clause'") ", has nothing to do with mapping. the SQL is not being >> understood by the database. from_statement() results in the SQL you >> pass being executed verbatim, and the issue with the statement is >> what >> I said earlier. >> >> On Apr 16, 2009, at 3:24 PM, dykang wrote: >> >> >> >>>> So above, you're joining "table2" to "s". the ON clause must be in >>>> terms of "table2" and "s", not "outside", which is meaningless in >>>> that >>>> context. >> >>> You are correct, that was a mistake in my example, but does not >>> change >>> my mapping error. >>> The error was not that the query it was creating was incorrect, but >>> that I was unable to map the results >>> back into my mapped classes. > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. 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 -~----------~----~----~----~------~----~------~--~---
