On Sep 2, 2010, at 6:51 PM, cd34 wrote:

> meta.Session.query(Job).order_by(Job.min_level).order_by(Job.descr).filter(Job.tier==1).outerjoin((User_job_progress,
> User_job_progress.job_id==Job.job_id)).filter(User_job_progress.fb_uid==1)
> 
> results in a query of:
> 
> FROM xxx_jobs LEFT OUTER JOIN xxx_user_job_progress ON
> xxx_user_job_progress.job_id = xxx_jobs.job_id
> WHERE xxx_jobs.tier = %s AND xxx_user_job_progress.fb_uid = %s ORDER
> BY xxx_jobs.min_level, xxx_jobs.descr
> 
> but, what I am trying to achieve is
> 
> FROM xxx_jobs LEFT OUTER JOIN xxx_user_job_progress ON
> (xxx_user_job_progress.job_id = xxx_jobs.job_id
> AND xxx_user_job_progress.fb_uid = %s) WHERE xxx_jobs.tier = %s ORDER
> BY xxx_jobs.min_level, xxx_jobs.descr
> 
> I tried putting the .filter within the outerjoin, but the tuple object
> has no attribute filter.  Adding a second condition results in
> ValueError: too many values to unpack.  Passing a list doesn't appear
> to be parsed as there is no attribute _from_objects.

you need to use and_(), and pass the criterion as a list inside, 

from sqlalchemy import and_
query.outerjoin((target, and_(foo.bar==q, bar.bat==x))


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