On Jun 26, 8:29 am, Michael Bayer <[EMAIL PROTECTED]> 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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to