I have tired to implement a many to many relationship from the online documentation and the example attached in the previous Many to Many thread but to no avail.
I am trying to following: CREATE TABLE roles ( rl_id BIGSERIAL NOT NULL PRIMARY KEY, rl_name TEXT NOT NULL, rl_desc TEXT NOT NULL, UNIQUE(rl_name) ) WITHOUT OIDS; CREATE TABLE users ( usr_id BIGSERIAL NOT NULL PRIMARY KEY, usr_logon TEXT NOT NULL, usr_name TEXT NOT NULL, usr_pp TEXT NOT NULL, UNIQUE(usr_logon) ) WITHOUT OIDS; CREATE TABLE users_x_roles ( usr_id BIGINT NOT NULL, rl_id BIGINT NOT NULL, PRIMARY KEY(usr_id,rl_id) ) WITHOUT OIDS; roles = Table('roles', db, Column('rl_id', Integer, Sequence('roles_id_seq', optional=False), primary_key=True), Column('rl_name', String, nullable=False), Column('rl_desc', String, nullable=False)) users_x_roles = Table('users_x_roles', db, Column('usr_id', Integer, ForeignKey('users.usr_id'), nullable=False), Column('rl_id', Integer, ForeignKey('roles.rl_id'), nullable=False)) users = Table('users', db, Column('usr_id', Integer, Sequence('users_id_seq',optional=False), primary_key=True), Column('usr_logon', String, nullable=False), Column('usr_pp', String, nullable=False), Column('usr_name', String, nullable=False)) assign_mapper(Role, tables.roles, properties={ 'rl_id': tables.roles.c.rl_id, 'name': tables.roles.c.rl_name, 'desc': tables.roles.c.rl_desc,}) assign_mapper(User, tables.users, properties={ 'usr_id': tables.users.c.usr_id, 'logon': tables.users.c.usr_logon, 'pp': tables.users.c.usr_pp , 'name': tables.users.c.usr_name, '_roles': relation(Role, secondary=tables.users_x_roles, primaryjoin=tables.users.c.usr_id==tables.users_x_roles.c.usr_id, secondaryjoin=tables.users_x_roles.c.rl_id==tables.roles.c.rl_id, lazy=False),}) Then when running the following: u = User.mapper.get(1) The following exception is raised: /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in init(self, *args, **kwargs) 224 except TypeError, msg: 225 # re-raise with the offending class name added to help in debugging --> 226 raise TypeError, '%s.%s' %(self.__class__.__name__, msg) 227 # override oldinit, insuring that its not already one of our 228 # own modified inits TypeError: User.len() of unsized object I'm at a loss as to what I'm doing incorrectly. Any suggestions? ---- FULL TRACE ---- exceptions.TypeError Traceback (most recent call last) /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in get(self, *ident) 273 key = objectstore.get_id_key(ident, self.class_) 274 #print "key: " + repr(key) + " ident: " + repr(ident) --> 275 return self._get(key, ident) 276 277 def _get(self, key, ident=None): /usr/lib/python2.4/site-packages/SQLAlchemy- 0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in _get(self, key, ident) 287 i += 1 288 try: --> 289 return self.select(self._get_clause, params=params)[0] 290 except IndexError: 291 return None /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in select(self, arg, **kwargs) 450 return self.select_statement(arg, **kwargs) 451 else: --> 452 return self.select_whereclause (arg, **kwargs) 453 454 def select_whereclause(self, whereclause=None, params=None, **kwargs): /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in select_whereclause(self, whereclause, params, **kwargs) 455 statement = self._compile(whereclause, **kwargs) 456 if params is not None: --> 457 return self.select_statement(statement, **params) 458 else: 459 return self.select_statement(statement) /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in select_statement(self, statement, **params) 468 def select_statement(self, statement, **params): 469 statement.use_labels = True --> 470 return self.instances(statement.execute(**params)) 471 472 def select_text(self, text, **params): /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in instances(self, cursor, *mappers, **kwargs) 252 if row is None: 253 break --> 254 self._instance(row, imap, result) 255 i = 0 256 for m in mappers: /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in _instance(self, row, imap, result, populate_existing) 750 instance = self.extension.create_instance(self, row, imap, self.class_) 751 if instance is None: --> 752 instance = self.class_(_mapper_nohistory=True) 753 imap[identitykey] = instance 754 isnew = True /usr/lib/python2.4/site-packages/SQLAlchemy-0.1.2-py2.4.egg/sqlalchemy/mapping/mapper.py in init(self, *args, **kwargs) 224 except TypeError, msg: 225 # re-raise with the offending class name added to help in debugging --> 226 raise TypeError, '%s.%s' %(self.__class__.__name__, msg) 227 # override oldinit, insuring that its not already one of our 228 # own modified inits TypeError: User.len() of unsized object