On Sep 12, 2008, at 9:42 AM, Werner F. Bruhin wrote:

> j1 = sao.outerjoin(db.Cellarbook, db.Cbvintage)
> print j1
>
> j2 = sao.outerjoin(db.Cbvintage, db.Cbbottle)
> print j2
>
> j3 = sao.outerjoin(db.Cellarbook,  
> db.Cbvintage).outerjoin(db.Cbvintage,
> db.Cbbottle)
> print j3
>
> j1 and j2 produce a join clause, but on j3 I get the following  
> exception:
>
>  File
> "c:\python25\lib\site-packages\sqlalchemy-0.5.0rc1-py2.5.egg 
> \sqlalchemy\sql\compiler.py",
> line 181, in process
>    meth = getattr(self, "visit_%s" % obj.__visit_name__, None)
> AttributeError: type object 'Cbbottle' has no attribute  
> '__visit_name__'
>
> What is the best/most efficient way of doing multiple joins with  
> SA.orm?
>

if CellarBook, Cbvintage, etc. are mapped classes, the join and  
outerjoin functions you must be using are "from sqlalchemy.orm import  
join, outerjoin".   those are aware of ORM mapped classes whereas  
sqlalchemy.sql.expression.join/outerjoin are not.

You can use the outerjoin() attached to Qeury for the whole thing, i.e.:

query(Class1).outerjoin(Class2, Class3)

if the ON condition is required:

query(Class1).outerjoin((Class2, Class1.foo==Class2.bar), (Class3,  
Class3.bar==Class2.foo))




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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