[help] Still Having problems with MultipleJoin

1 view
Skip to first unread message

Michael Schneider

unread,
Dec 1, 2005, 9:49:59 AM12/1/05
to TurboGears
I am still having problems adding/accessing objects and Multiple Join.

I think I am following the instructions/help:

Assumption:

1) Creating The TestCase Object, with the argument owner=myOwner
establishes both sides of the 1 to Many relationship specified by the
MultipleJoin.


Is this assumption correct?

I pulled a simple standalone test from turbogears. When I run it I
get:

If this is correct, can someone do me a favor and run the sample code
on their machine and see if it works.

1) it is standalone
2) it uses a memory database
3) you can uncomment the debug line if you want to see the SQL commands

Thanks for helping a SQLObject Newbie,
Mike

----------------------- Output
------------------------------------------
<TestCase 1 name='test 1' ownerID=1>
<TestCaseOwner 1 name='owner 1'>
Traceback (most recent call last):
File "C:\devTesting\devtesting\devtesting\testing.py", line 29, in ?
print owner_1.tests
File "<string>", line 1, in <lambda>
File
"c:\python24\lib\site-packages\SQLObject-0.7.0-py2.4.egg\sqlobject\joins.py",
line 131, in performJoin
inst.id)
File
"c:\python24\lib\site-packages\SQLObject-0.7.0-py2.4.egg\sqlobject\dbconnection.py",
line 592, in _SO_selectJoin
return self.queryAll("SELECT %s FROM %s WHERE %s = %s" %
File
"c:\python24\lib\site-packages\SQLObject-0.7.0-py2.4.egg\sqlobject\dbconnection.py",
line 316, in queryAll
return self._runWithConnection(self._queryAll, s)
File
"c:\python24\lib\site-packages\SQLObject-0.7.0-py2.4.egg\sqlobject\dbconnection.py",
line 217, in _runWithConnection
val = meth(conn, *args)
File
"c:\python24\lib\site-packages\SQLObject-0.7.0-py2.4.egg\sqlobject\dbconnection.py",
line 309, in _queryAll
self._executeRetry(conn, c, s)
File
"c:\python24\lib\site-packages\SQLObject-0.7.0-py2.4.egg\sqlobject\dbconnection.py",
line 295, in _executeRetry
return cursor.execute(query)
pysqlite2.dbapi2.OperationalError: no such column: test_case_owner_id


------- Sample Standalone program ------------------------

from sqlobject import *
import pysqlite2.dbapi2

class TestCaseOwner(SQLObject):
name = StringCol(alternateID=True)
tests = MultipleJoin('TestCase')

class TestCase(SQLObject):
name = StringCol(alternateID=True)
owner = ForeignKey('TestCaseOwner')

connection_string = 'sqlite:/:memory'
connection = connectionForURI(connection_string)
sqlhub.threadConnection = connection
#connection.debug = True

TestCase.dropTable(ifExists=True)
TestCaseOwner.dropTable(ifExists=True)
TestCase.createTable(ifNotExists=True)
TestCaseOwner.createTable(ifNotExists=True)

new_owner = TestCaseOwner(name="owner 1")
TestCase(name="test 1", owner = new_owner)

test_case_1 = TestCase.byName("test 1")
print test_case_1
owner_1 = TestCaseOwner.byName("owner 1")
print owner_1
print owner_1.tests

Lee McFadden

unread,
Dec 1, 2005, 10:27:19 AM12/1/05
to turbo...@googlegroups.com
Mike,

You would need to make the following change:

class TestCaseOwner(SQLObject):
name = StringCol(alternateID=True)
tests = MultipleJoin('TestCase', joinColumn='owner_id')

If you had called your owner attribute in TestCase: 'testCaseOwner' it
would have worked automatically. While SQLObject is good at guessing
in most cases, it can't get it right all the time. :)

Lee

Michael Schneider

unread,
Dec 1, 2005, 10:35:48 AM12/1/05
to TurboGears
Lee,

Thank you very much, that was the missing link. I changed the field
name and it worked great!!!!

Mike

Reply all
Reply to author
Forward
0 new messages