Hi, I have trouble getting SimpleJoin to work. I currently use SQLObject 0.9.0.
This is an excerpt from my model: class User(SQLObject): class sqlmeta: table = "usr_User" idName = "usr_Id" display_name = UnicodeCol(length=255, dbName="usr_DisplayName") [...] end_user = SingleJoin("EndUser", joinColumn="eus_usr_Id") class EndUser(SQLObject): class sqlmeta: table = "eus_EndUser" idName = "eus_Id" user = ForeignKey("User", dbName="eus_usr_Id") [...] Issuing the following code: >>> u = User.get(8) >>> e = u.end_user Gives: Traceback (most recent call last): File "<console>", line 1, in ? File "<string>", line 1, in <lambda> File "C:\Python24\lib\site-packages\sqlobject-0.9.0-py2.4.egg\sqlobject\joins.py", line 312, in performJoin results = self.otherClass.select( File "c:\python24\lib\site-packages\SQLObject-0.9.0-py2.4.egg\sqlobject\sqlbuilder.py", line 381, in __getattr__ raise AttributeError("%s instance has no attribute '%s'" % (self.soClass.__name__, attr)) AttributeError: EndUser instance has no attribute 'eusUsrId' If I change the definition of the foreign key in EndUser to use MultipleJoin, like this, it all seems to work allright: end_user = MultipleJoin("EndUser", joinColumn="eus_usr_Id") Now I can do this: >>> u = User.get(8) >>> e = u.end_user[0] The value of e is now what I expect. Some investigation of the code in SQLObject revealed that the implementations of the method performJoin inside SOSingleJoin and SOMultipleJoin use quite different approaches. I tried modifying performJoin in the SOSingleJoin class to do something similar to the one in SOMultipleJoin, resulting in this code: def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, inst.id) if inst.sqlmeta._perConnection: conn = inst._connection else: conn = None if len(ids) == 0: return None result = self.otherClass.get(ids[0][0], conn) return result Now things work like I would expekt. Have I misunderstood the concept of how SimpleJoin columns works, or is the implementation outdated? Tom ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss