From: Jeff W. <je...@me...> - 2005-10-27 12:48:44
|
While working on the identity framework for TurboGears, I've been trying to come up with a clean way to allow developers to provide their own identity model classes. One thought was to load the name of the developer's preferred User class and instantiate that instead of the default User class. So this means I have the following model: class User(SQLObject): class sqlmeta: table="user_table" # meaningful columns left out for brevity groups=RelatedJoin( "Group", intermediateTable="user_group", joinColumn="user_id", otherColumn="group_id" ) class Group(SQLObject): class sqlmeta: table="group_table" # meaningful group info left out for brevity users=RelatedJoin( "User", intermediateTable="user_group", joinColumn="group_id", otherColumn="user_id" ) All works great so far. But then I add an override for the User class to the config file to specify MyUser instead of User. MyUser is defined as: class MyUser(User): # additional package specific stuff However, when I instantiate a MyUser object and add it to a group, attempting to retrieve the list of groups for that object results in an Exception: miles:~/Sites/turbo/cms> tg-admin shell Python 2.4.1 (#2, Mar 31 2005, 00:05:10) [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> u= MyUser.get(1) >>> u <MyUser 1 userId='jeff' password='xxxx' emailAddress='je...@me...' displayName='Jeff Watkins' created='datetime.datetime...)' age=0> >>> u.groups Traceback (most recent call last): File "<console>", line 1, in ? File "<string>", line 1, in <lambda> IndexError: list index out of range >>> Now I suppose this is caused by the join relating Users and Groups, but I would have expected (wrongly, I guess) that a relation between MyUser and Groups would automatically be created by inheriting the RelatedJoin in User. What am I missing here? -- Jeff Watkins http://metrocat.org/ 'I know about people who talk about suffering for the common good. It's never bloody them! When you hear a man shouting "Forward, brave comrades!" you'll see he's the one behind the bloody big rock and the one wearing the only really arrow-proof helmet!' -- Rincewind gives a speech on politics. (Terry Pratchett, Interesting Times) |