From: Oleg B. <ph...@ph...> - 2005-09-12 14:31:50
|
On Mon, Sep 12, 2005 at 10:39:55AM +0200, Andreas Kostyrka wrote: > from sqlobject import * > > import os > os.unlink("/tmp/stest") > __connection__ = dbconnection.connectionForURI("sqlite:///tmp/stest") > > class Customer(SQLObject): > name = StringCol() > > class Task(SQLObject): > name = StringCol() > > class Test(SQLObject): > customer = ForeignKey('Customer') > task = ForeignKey('Task') > def _set_customer(self, val): > print "VAL", val > self._SO_set_customer(val) > > Customer.createTable(ifNotExists=True) > Task.createTable(ifNotExists=True) > Test.createTable(ifNotExists=True) > cust = Customer(name="cust1") > task = Task(name="Task1") > > Test(customer=cust, task=task) > > My understanding is, that it should print something, right? > It does not :( I've found the source of the bug but havn't commited a patch yet. Ian, there is the code in ._create(): # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # If a foreign key is given, we get the ID of the object # and put that in instead if kw.has_key(column.foreignName): kw[column.name] = getID(kw[column.foreignName]) del kw[column.foreignName] because of which .set() gets different parameters in cases Test(customer=cust, task=task) and Test.set(customer=cust, task=task) I'd like to remove that manipulation in the inner "if" (and fix the next "if" after it). This allow to call setters for ForeignKeys in .set() called from __init__()/_create(). Any opinion on this? The change seems rather big considering we are in beta... Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |