Sam Nilsson wrote:
> Hello,
>
> I am new to sqlobject, and i'm finding it to be a truly wonderful layer
> and model. I have had some problems with RelatedJoin attributes and I
> have seen some talk of that recently on the list. The suggestion to
> explicitly define joinColumn, otherColumn, and joinMethodName solved a
> few different problems that I was having.
>
> Unsolved Problems - I have pasted my 'Group' class below. If I do a
> dir(Group), I see attributes for 'admins' 'users' and more. I also see
> the methods 'addUser' and 'removeUser', *but* there are no corresponding
> 'addAdmin' and 'removeAdmin' methods!
>
> I have gathered from the list that the current revision in subversion
> solves some of these problems but may not solve all of them. I am not
> familiar with the state of development, so I want to ask, should I
> update to the newest revision? Is it more stable and less buggy than v.6?
>
> Can anyone help with info about my problem? If the consensus is to
> update to a newer sqlobject, then I will do so and report back.
>
> Thanks for any help!
> - Sam Nilsson
>
>
> from sqlobject import *
> from Store import conn
>
> class Group(SQLObject):
>
> _table = "group_table"
> _connection = conn
>
> name = StringCol()
> description = StringCol()
>
> users = RelatedJoin("User",
> intermediateTable='group_table_user', joinColumn='group_table_id',
> otherColumn='user_id', joinMethodName='users')
> admins = RelatedJoin("User",
> intermediateTable='group_table_admin', joinColumn='group_table_id',
> otherColumn='user_id', joinMethodName='admins')
> categories = MultipleJoin("Category", joinColumn='group_id',
> joinMethodName='categories')
>
I don't know why nobody wrote back to me. Maybe because my answer was
already in the online documentation! I was missing the totally important
addRemoveName='alternateName'
My new and working Group class looks like this now:
from sqlobject import *
from Store import conn
class Group(SQLObject):
_table = "group_table"
_connection = conn
name = StringCol()
description = StringCol()
users = RelatedJoin("User",
intermediateTable='group_table_user',
joinColumn='group_table_id',
otherColumn='user_id',
joinMethodName='users')
admins = RelatedJoin("User",
intermediateTable='group_table_admin',
joinColumn='group_table_id',
otherColumn='user_id',
joinMethodName='admins',
addRemoveName='Admin')
#### addRemoveName above allows sqlobject to create
#### addAdmin() and removeAdmin() methods
categories = MultipleJoin("Category",
joinColumn='group_id',
joinMethodName='categories')
|