9 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Beginner: query.join...| From | Sent On | Attachments |
|---|---|---|
| bukzor | 24 Jun 2008 18:22 | |
| Kyle Schaffrick | 24 Jun 2008 23:51 | |
| bukzor | 25 Jun 2008 00:23 | |
| Kyle Schaffrick | 25 Jun 2008 01:43 | |
| bukzor | 25 Jun 2008 10:24 | |
| Michael Bayer | 25 Jun 2008 10:50 | |
| bukzor | 26 Jun 2008 08:12 | |
| Michael Bayer | 26 Jun 2008 08:28 | |
| bukzor | 26 Jun 2008 08:43 |
| Subject: | [sqlalchemy] Re: Beginner: query.join not cooperating![]() |
|---|---|
| From: | bukzor (work...@gmail.com) |
| Date: | 06/26/2008 08:43:41 AM |
| List: | com.googlegroups.sqlalchemy |
On Jun 26, 8:29 am, Michael Bayer <mike...@zzzcomputing.com> wrote:
On Jun 26, 2008, at 11:12 AM, bukzor wrote:
Sorry for being a pest, but I've looked at the documentation and really can't figure this out. If a mapped class is a node of our graph, where do I find the edges, and how do I get to the next node.
the mapper has a method called "iterate_properties" which returns all MapperProperty objects it contains. Each PropertyLoader subclass represents a relation() to another mapper.
so you can walk among relations as follows:
recursive = set() def walk (cls): print "cls:", cls if cls in recursive: return recursive.add(cls)
mapper = class_mapper(cls) for prop in mapper.iterate_properties: if isinstance(prop, PropertyLoader): print "key", prop.key walk(prop.mapper.class_)
Alternatively, should I do this at the table/sql level rather than the class/orm level?
it depends on what information you're interested in. the use case here seems to be joining among configured relation()s so the ORM level would be better.
How did you yourself learn this? Is there some other reference I'm overlooking?
heres the docs for every API mentioned above:
The same documentation can be had by using "pydoc <modulename>", i.e. pydoc sqlalchemy.orm.mapperlib
I also think you should consider carefully if you truly need automatic, implicit joining across arbitrarily long paths. Its a feature we explicitly removed for its non-pythonicness and unpredictable behavior.
Thanks so much for the help!
I need it because the interface I'm exposing lets (advanced) users select filters against arbitrary fields in the database. From these filters I need to construct a sql query. The "easy" way is just to always join every table in the database, but this is infeasible because the size of the database would make this query very slow. So, I need to figure out some sort of smart auto-join method. I'll only define one path between each table, so the result will be deterministic.
I'm open to suggestions if you see a better way.
I'll let you know how it goes...
--Buck
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqla...@googlegroups.com
To unsubscribe from this group, send email to
sqla...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---




