[SQLObject] Re: Hi guys. Please, I need help
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: fingerclick <fc...@bo...> - 2004-04-22 04:36:53
|
Scott Russell wrote:
> On Wed, 2004-04-21 at 14:17, fingerclick wrote:
>
>>I´d like to put in one table two references do a same table. Does
>>sqlObject allows that? Or may i build the sql in another way to
>>make that works? db_login has the names and db_request has 2 fields that
>>point to db_login( these fields are the persons id ).Thanks in advance.
>
>
> Unless I misunderstand the problem, if you take the time to discover how
> to add one reference field, it is the exact same process to add another.
>
> class request(SQLObject):
> NewFile = BoolCol(default=1)
> DbRequestId = ForeignKey('Login')
> DbSourceId = ForeignKey('Login')
> ts = DateTimeCol()
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
Thanks man. But i think i still have a problem. The "DbRequestId" and
the "DbSourceId" fields are linking to table Login. So, wouldn't
DbRequestId and DbSourceId have to be renamed to Login? So, this is the
point: i have two fields pointing to the same table. Take a look at my code:
from SQLObject import *
__connection__ = PostgresConnection('user=my_user dbname=my_user')
class Login(SQLObject):
firstName = StringCol()
middleInitial = StringCol(length=1, default=None)
lastName = StringCol()
addresses = MultipleJoin('db_request')
class db_request(SQLObject):
new_file = BoolCol(default=1)
DbRequestId = ForeignKey('Login')
DbSourceId = ForeignKey('Login')
def reset():
Login.dropTable(ifExists=True)
Login.createTable()
db_request.dropTable(ifExists=True)
db_request.createTable()
reset()
p1 = Login.new(firstName='John', lastName='Doe')
p2 = Login.new(firstName='Cal', lastName='Robson')
r1 = db_request.new( new_file='t', DbRequestId=p1, DbSourceId=p2 )
-> And it reported the following error:
Traceback (most recent call last):
File "tt.py", line 27, in ?
r1 = db_request.new( new_file='t', DbRequestId=p1, DbSourceId=p2 )
File "/usr/lib/python2.3/site-packages/SQLObject/SQLObject.py", line
907, in new
inst._SO_finishCreate(id, connection=connection)
File "/usr/lib/python2.3/site-packages/SQLObject/SQLObject.py", line
929, in _SO_finishCreate
id, names, values)
File "/usr/lib/python2.3/site-packages/SQLObject/DBConnection.py",
line 163, in queryInsertID
return self._runWithConnection(self._queryInsertID, table, idName,
id, names, values)
File "/usr/lib/python2.3/site-packages/SQLObject/DBConnection.py",
line 74, in _runWithConnection
val = meth(conn, *args)
File "/usr/lib/python2.3/site-packages/SQLObject/DBConnection.py",
line 629, in _queryInsertID
q = self._insertSQL(table, names, values)
File "/usr/lib/python2.3/site-packages/SQLObject/DBConnection.py",
line 155, in _insertSQL
return ("INSERT INTO %s (%s) VALUES (%s)" %
File "/usr/lib/python2.3/site-packages/SQLObject/DBConnection.py",
line 348, in sqlrepr
return sqlrepr(v, self.dbName)
File "/usr/lib/python2.3/site-packages/SQLObject/Converters.py", line
177, in sqlrepr
raise ValueError, "Unknown SQL builtin type: %s for %s" % \
ValueError: Unknown SQL builtin type: <class '__main__.Login'> for
<Login 2 lastName='Robson' middleInitial=None firstName='Cal'>
Thanks in advance for all help, im a little confused about this and i
really need it. : (
|