Janzert schrieb:
> 2. Why not something like the following (untested code)?
>      @property
>      def permissions(self):
>          p_q = session.query(Permission).join(['tg_group', 'tg_user'])
>          p_q.filter_by(user_id = self.user_id)
>       return p_q.all()

I would write something like that in a long statement, without the 
arbitrary p_q variable and avoid using hard coded table names.

The other problem is that this code doesn't work at all.

Also, the method must return a set, not a list with duplicates.

There are basically two ways to collect the permissions via SQL.

Either you make the two joins, creating all possible ways a user can 
have a certain permission, and then remove the duplicates, like that:

     def permissions(self):
         return set(Permission.query.join(Permission.groups,
             Group.users).filter_by(user_id=self.user_id).all())

Or you create the query using exist clauses, so that the query does not 
produce any duplicates in the first place:

     def permissions(self):
         return set(Permission.query.filter(Permission.groups.any(
             Group.users.any(User.user_id==self.user_id))).all())

The problem with this latter solution only works with SA >= 0.4 (and the 
former solution even only with SA >= 0.5).

(Also, both solutions do a last join with the user table that is 
actually unnecessary. I currently see no elegant way to avoid this. It 
does not harm much, though.)

-- Christoph




--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to