Hi,
I have a schema that shall contain association attributes, i.e. some
"many to many" have more than 2 columns. I implement this in sqlobject
by declaring explicitly the intermediate table (table 'Foo' below) and
the attributes (column 'attr' below).
My problem is that some attributes shall have default values (like the
current timestamp for example) but they do not get the default value
from the declaration when I use the generated "addName" method.
Is this a "patches are welcome" or is there another way?
I also tried to dynamically add the columns with SQL but sqlite
doesn't support "add column default current_timestamp". My only
solution is to run my script to generate the partial schema, dump it,
modify/edit it, and rerun my script. This is extremely unfriendly.
------------------------------------------------------------------------------
import sqlobject as so
so.sqlhub.processConnection = so.connectionForURI('sqlite:/:memory:')
class Hello(so.SQLObject):
i = so.IntCol(default=123)
world = so.RelatedJoin('World', intermediateTable='foo')
class World(so.SQLObject):
i = so.IntCol(default=123)
hello = so.RelatedJoin('Hello', intermediateTable='foo')
class Foo(so.SQLObject):
hello = so.ForeignKey('Hello')
world = so.ForeignKey('World')
attr = so.StringCol(default='abc')
for cls in [Hello, World, Foo]:
cls.createTable(ifNotExists=True, createJoinTables=False)
h=Hello()
w=World()
h.addWorld(w)
f=Foo.get(1)
print f.attr
------------------------------------------------------------------------------
conf: win32, py2.4, SQLObject-0.7.1dev_r1457-py2.4.egg, pysqlite 2.2.2
--
jt