On 9/29/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Is there a way to select from a related join using a conditional?
>
> For example suppose the User class has a related join called 'friends'.
>
> class User:
> ...
> friends = relatedJoin(...)
It looks as if you have only half of your relatedJoin defined: you
have the half that says "all Users that this User has designated as a
friend", but you are missing the half that says "all Users that have
designated this User as a friend".
An example might help:
class User(SQLObject):
name = UnicodeCol(length=40)
friends = RelatedJoin('User',
joinColumn='fan',
otherColumn='friend',
intermediateTable='friends',
addRemoveName='Friend')
fans = RelatedJoin('User',
joinColumn='friend',
otherColumn='fan',
intermediateTable='friends',
addRemoveName='Fan')
'friends' means 'all the Users that this User has designated as
friends'; 'fans' means 'all the Users that have designated this User
as a friend.'
>>> joe = User(name="Joe")
>>> mike = User(name="Mike")
>>> joe.addFriend(mike)
>>> joe.friends, joe.fans
([<User 2 name=u'Mike'>], [])
>>> mike.friends, mike.fans
([], [<User 1 name=u'Joe'>])
As a side note, if you do want to select on a related join, use the
SQLRelatedJoin class instead of the RelatedJoin class. Instead of
returning a list of objects, SQLRelatedJoin returns a SelectResults
object, which you can then count, filter, aggregate, etc.
--
Tim Lesher <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---