9 messages in com.googlegroups.sqlalchemy[sqlalchemy] Re: Beginner: query.join...
FromSent OnAttachments
bukzor24 Jun 2008 18:22 
Kyle Schaffrick24 Jun 2008 23:51 
bukzor25 Jun 2008 00:23 
Kyle Schaffrick25 Jun 2008 01:43 
bukzor25 Jun 2008 10:24 
Michael Bayer25 Jun 2008 10:50 
bukzor26 Jun 2008 08:12 
Michael Bayer26 Jun 2008 08:28 
bukzor26 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:

http://www.sqlalchemy.org/docs/05/sqlalchemy_orm.html#docstrings_sqla...http://www.sqlalchemy.org/docs/05/sqlalchemy_orm_mapper.html#docstrin...http://www.sqlalchemy.org/docs/05/sqlalchemy_orm_interfaces.html#docs...http://www.sqlalchemy.org/docs/05/sqlalchemy_orm_properties.html#docs...

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