On Sun, 2006-10-01 at 22:29 +0000, [EMAIL PROTECTED] wrote:
> Is it possible to do a select on the groups with a condition that the
> user's table contains a specific user?

To get a list of groups containing a given user, you would do:

my_user.groups

However if you want this information in SelectResults object (because,
for example you want to display it in a fast data grid), you have two
choices.  

One is to change your model to use an SQLRelatedJoin instead of a
RelatedJoin.  This is not ideal if you want one format some of the time,
and the other format the rest, as if you have both columns SQLObject
will try to create two join tables with the same name.  You can prevent
this by adding createRelatedTable=False in your column definition for
one of the columns, and creating the tables will work fine, but it will
still complain when your try to drop the tables.

The other (less succinct, slower, but easier, and more understandable)
option is to use the IN function:

from sqlbuilder import IN

model.Group.select(IN(model.Group.q.id, [group.id for group in
my_user.groups]))

HTH

> I wasn't able to find in the sql documentation how to do this.
> 
> The psuedocode i have is:
>               selectGroups =
> model.Groups.select(model.Groups.users.__contains__(selectUser.id)
> 
> Of course .__contains__ is not correct sql syntax...
> 
> 
> > 
-- 
Peter S Russell <[EMAIL PROTECTED]>
Qustom


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to