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!"
Dan Lenski <dlenski <at> gmail.com> writes:
> Thank you Oleg! I read through that example, and tried it out... but what
> I don't see is that this makes it more convenient to access the
> intermediate table.
>
> With the database schema in the example in the FAQ, I can do:
>
> me=User.get(1)
> myroles=me.roles
>
> But there's no easy way to find out which of the roles are marked as
> active:
>
> for r in myroles:
> print "Role is active? ", r.active # error
>
> How would I now find out the active roles, given a User instance?
> Thanks!
>
> 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