Just thought of something... this statement can be removed from the example:

"Also assume that in your app, all users belong to only one group."

I thought about None duplicates, but there should be none. Other groups 
should be filtered out by the belongs part of the left join for the 
auth_group. 

On Monday, 10 December 2012 14:48:16 UTC-5, Magnitus wrote:
>
> I must have spent a good hour hammering at this before I got it right.
>
> Maybe rephrase it a bit, but I think it's a good example...
>
> Assume that you want all users returned, but want to outline specifically 
> those belonging to group A or B (with the others having their group set to 
> None) in one query.
>
> Also assume that in your app, all users belong to only one group.
>
> It can be done with the following:
>
> left=db.auth_membership.on(db.auth_user.id
> ==db.auth_membership.user_id),db.auth_group.on((db.auth_group.id==db.auth_membership.group_id)&db.auth_group.role.belongs(("Group
>  
> A","Group B"))) 
> Users = db().select(db.auth_user.ALL, db.auth_group.ALL, left=left)
>

-- 



Reply via email to