[Twisted-Python] twisted.enterprise.row multiple rowForeignKeys

Vincent AE Scott twisted at codex.net
Wed Jun 1 09:47:04 EDT 2005


Hi,
First off, I'm a relative newby to twisted and I've just encountered my
first problem that i couldnt solve either via the docs or google.

I'm using twisted 2.0, python 2.4.1 on debian/testing

namely I'm attempting to use twisted.enterprise.row and add multiple
foreign kets to a RowObject.  What i thought would work is the
following:

 rowForeignKeys	= [
  ("questions", [("question_id","int")], [("id_question","int")], None, 1),
  ("users", [("user_id","int")], [("id_user","int")], None, 1),
 ]

But, what i find works is when i only have one foreign reference in my
class.  Both of the above ones are valid (see attached source), but only
the first one (questions) is actually used.  If i comment out the
questions entry, leaving just "users" it works as expected.

I popped in some extra debug in Reflector.populateSchemaFor to verify
that it was processing both entries, and it appears to be so.

Does anyone else have a suggestion as to where I'm going wrong?

TIA
-v


-- 
keys:  http://codex.net/gpg.asc 

 Nothing is true && everything is possible

-------------- next part --------------
from twisted.enterprise import row

class QuestionRow( row.RowObject ):
	rowColumns = [
		("id_question","int"),
		("the_question","varchar"),
		("poser_id","int")
		]
	rowTableName	= "questions"
	rowKeyColumns	= [("id_question","int")]
	rowForeignKeys	= [("users", [("poser_id","int")], [("id_user","int")], None, 1)]
	
#######################################################################################

class AnswerRow( row.RowObject ):
	rowColumns = [
		("id_answer","int"),
		("question_id","int"),
		("the_answer","varchar"),
		("user_id","int")
		]
	rowTableName	= "answers"
	rowKeyColumns	= [("id_answer","int")]
	rowForeignKeys	= [
		("users", [("user_id","int")], [("id_user","int")], None, 1),
		("questions", [("question_id","int")], [("id_question","int")], None, 1),
		]

#######################################################################################

class UserRow( row.RowObject ):
	rowColumns = [
		("id_user",		"int"),
		("username",		"varchar"),
		("forename",		"varchar"),
		("surname",		"varchar")
		]
	rowTableName	= "users"
	rowKeyColumns	= [("id_user","int")]

#######################################################################################

from twisted.enterprise import adbapi
from twisted.internet import reactor, defer, task
from twisted.enterprise.sqlreflector import SQLReflector
from twisted.trial.util import deferredResult

dbpool = adbapi.ConnectionPool( "pyPgSQL.PgSQL", database='xxxx', \
	host='localhost', user='xxxx', password='xxxx' )

reflector = SQLReflector( dbpool, [UserRow, PrimaryGroupRow, QuestionRow, AnswerRow] )

def gotUsers(users):
	for user in users:
		for child in user.childRows:
			print "KEYS: ", child.rowForeignKey
			# this will only print the foriegn key descriptions 

def runme():
	d2 = reflector.loadObjectsFrom( "users" )
	d2.addCallback( gotUsers )
	deferredResult(d2)
	print "runme got deferred d2"

reactor.callLater( 1.0, runme )
reactor.run()



More information about the Twisted-Python mailing list