Thanks Michael.

On Oct 28, 1:21 am, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
> Kalium wrote:
>
> > Hi,
> > Just wondering if there is an easy way to determine what tables are
> > joined in a query?
>
> > I'm doing something like this
>
> > query = session.query(System, dynamic_obj).select_from(self.j)
>
> > Where dynamic_obj could be any mapped object and self.j represents a
> > join produced by the sqlalchemy.schema.Table.join() function. I'd like
> > to know if the table represented by dynamic_obj is already in the
> > self.j
>
> > I could of course do this programmatically outside of sqla, but it
> > would be nice if sqla could tell me this.
>
> here's how to do it like a pro
>
> from sqlalchemy.sql import visitors
>
> t1 = set()
> visitors.traverse(
>     object_mapper(dynamic_obj).mapped_table,
>     {},
>     {'table':t1.add}
> )
>
> t2 = set()
> visitors.traverse(self.j, {}, {'table':t2.add})
>
> tables_that_are_in_both = t1.intersection(t2)
>
> there's also a function sqlalchemy.sql.util.find_tables(expr) that does
> the "visitors.traverse" thing for you.
>
>
>
> > Cheers
--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to