On Wed, 13 Dec 2006 16:32:24 -0600, Luke Opperman hath writ:

> Depending on what you're actually trying to do, there's a few options. One, if
> you just want filtered results (like user.activeRoles), that's a simple filter
> on user.roles. If you really want to loop over all roles and get information
> from the intermediate table, you probably want both a SQLRelatedJoin and a
> SQLMultipleJoin.
> 
> class User(SQLObject):
>   roles = SQLRelatedJoin('Role', intermediateTable=...)
>   userRoles = SQLMultipleJoin('UserRole', ...)
> 
>   def _get_activeRoles(self):
>     import UserRole # obv not needed if all classes defined in this file
>     return self.roles.filter(UserRole.q.active==True)
> 
> for urole in aUser.userRoles:
>   print "role", urole.role.name, "is active?", urole.active
> 
> for role in aUser.activeRoles:
>   print "role", role.name, "is active!"
> 

Luke, thanks a lot!  That's just about exactly what I'm looking for. 
What the filter function is doing actually seems pretty complex: it
automatically figures out how to JOIN self.roles to the UserRoles table.

One thing I'm wondering: is there some source of documentation that I'm
missing? The filter() method doesn't seem to be described anywhere in the
official docs at http://www.sqlobject.org/SQLObject.html

Dan


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to