Janzert schrieb:
> My understanding and testing seem to show that an inner join doesn't
> return duplicates. Wrapping the result in a set doesn't seem necessary.

The query creates duplicates, and they are pulled from the database, but 
they are removed by SQLAlchemy because you are querying object instances 
and it makes no sense for SQLAlchemy to deliver duplicates in this case.

Nevertheless, the result should be converted to a set for backward 
compatibility and performance reasons  - you usually check for a certain 
permission with "in", and that will be faster for a set than for a list.

> After playing around with SA 0.3.10, 0.4.6 and 0.5.0beta1 and taking
> into account your comments I came up with this.
> 
>      def permissions(self):
>          return Permission.query.join(["groups",
>              "users"]).filter_by(user_id=self.user_id).all()
>      permissions = property(permissions)

Yes, this seems to work with all these SA versions. And the names in the 
join here are attribute names, not table names, so this is ok.

Still, this join query produces more results than necessary. You can 
verify this by using count() instead of all() - you will see more 
results counted than elements in the list. As I explained above, the 
duplicates are filtered away by SQLAlchemy because the query requests 
object instances, that's why you don't see them. So a solution using 
"any" (exist clauses) may still be more performant.

(Of course ehis is all a bit theoretical since users are usually not in 
hundreds of groups, but we should try to do it right anyway.)

-- Christop

--~--~---------~--~----~------------~-------~--~----~
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