yeah...this is totally fine for you to use, but i dont want to change  
SA to this, particularly becuase it forces a change to the return  
signature of join_via...it makes an arbitrary alias, and returns  
three objects back to you which now you have to use in the criterion,  
trust me nobody's going to bother trying to deal with that.  better  
to have people just construct exactly the criterion they want  
explicitly (using their own manually-constructed alias) and feed it  
in.  join_via/join_to/etc. are just shortcuts for common cases  
(therefore, probably not very useful for your purposes).

On Feb 15, 2007, at 1:54 PM, [EMAIL PROTECTED] wrote:

>
> final, ok for indirect recursion too .
>
> ##########
> import sqlalchemy
>
> def join_via( keys, mapper):
>     '''Query.join_via, input root mapper, return last mapper/table;
>         alias and link properly recursive /self-referential joins
>     '''
>     clause = None
>     c = None
>     self_table = None
>     self_colequivalents = None
>     xmappers = [mapper]        #mapper === parent
>     for key in keys:
>         prop = mapper.props[key]
>         c = prop.get_join( mapper)  #SA rev>=2285
>
>         parent_table = self_table
>         self_table = prop.target
>         parent_colequivalents = self_colequivalents
>         self_colequivalents =
>                   prop.mapper._get_inherited_column_equivalents()
>
>         print key,prop.primaryjoin,prop.foreignkey,prop.remote_side
>
>         if prop.mapper in xmappers:
>             self_table = self_table.alias()
>             print '>>', self_table.name
>             c.accept_visitor( sqlalchemy.sql_util.ClauseAdapter(
>                 self_table, include=prop.remote_side,
>                 equivalents= self_colequivalents
>             ))
>             xmappers.append( prop.mapper)
>         if mapper in xmappers:
>             if parent_table:
>                 c.accept_visitor( sqlalchemy.sql_util.ClauseAdapter(
>                     parent_table, include=prop.foreignkey,
>                     equivalents= parent_colequivalents
>                 ))
>         print '>>>', c
>
>         if clause is None:
>             clause = c
>         else:
>             clause &= c
>
>         mapper = prop.mapper
>
>     return clause, mapper, self_table
>
> ##########
> Anyone interested in the resulting expression-translator?
> It is independent from the sawrap-per, although will be used inside.
> e.g. convert plain python-func/method
> def myfilter( person):
>   return ( (person.friend.address.owner.friend.age > 20)
>           & person.name.startswith('a') )
> into SA-query...
>
> >


--~--~---------~--~----~------------~-------~--~----~
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