On 05/25/2016 02:15 PM, Andrew Pashkin wrote:
On 05/25/2016 08:36 PM, Mike Bayer wrote:
You need to be using join() and not joinedload() here.   You shouldn't
care about the columns or syntaxes that joinedload() renders.  Search
the docs for "the zen of eager loading",

Yes, I know that, but with join() my question still relevant. What I
want to do is for given column name  and an arbitrary SA query -
retrieve unambiguous reference to the actual column of that query with
priority to those columns, which are "closer" to the root SELECT.


So for SELECT foo.name, bar.name FROM foo LEFT JOIN bar ON ... and
column name "name", I would like to build a function, that would return
a reference to a column object for foo.name.

Part of what you're asking is exactly something SQLAlchemy Core can do very well, the "priority to the column that's "closer" to the root SELECT" part, and the other part is not possible: "given "name", magically know that I want "name" from Foo, not Bar".

What heuristic would be used to know that "name" is for Foo and not Bar ? (why do you even need this?) If you're going by, "I know that Foo is first and Bar is second", that's brittle - what makes Foo be first? That part of the program that happens to put "Foo.name" first should instead be tagging "Foo.name" as important in some way that is more explicit than just "it happens to be first". An annotation is one way this could be done (e.g. the _annotate() method).









--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to