except KeyError:
if mustexist:
raise "Table '%s.%s' not defined" % (schema, name)
- table = type.__call__(self, name, engine, *args, **kwargs)
+ table = type.__call__(self, name, engine, **kwargs)
engine.tables[key] = table
# load column definitions from the database if 'autoload' is defined
# we do it after the table is in the singleton dictionary to support
# circular foreign keys
if autoload:
engine.reflecttable(table)
-
+ # initialize all the column, etc. objects. done after
+ # reflection to allow user-overrides
+ table._init_items(*args)
return table
Be sure to look at sqlalchemy.sql.TableImpl for additional methods defined on a Table."""
__metaclass__ = TableSingleton
- def __init__(self, name, engine, *args, **kwargs):
+ def __init__(self, name, engine, **kwargs):
"""Table objects can be constructed directly. The init method is actually called via
the TableSingleton metaclass. Arguments are:
self.primary_key = []
self.engine = engine
self._impl = self.engine.tableimpl(self)
- self._init_items(*args)
self.schema = kwargs.pop('schema', None)
if self.schema is not None:
self.fullname = "%s.%s" % (self.schema, self.name)
assert not pgtable.c.name.nullable
assert pgtable.c.description.nullable
+ def testoverride(self):
+ table = Table(
+ 'override_test', testbase.db,
+ Column('col1', Integer, primary_key=True),
+ Column('col2', String(20)),
+ Column('col3', Numeric)
+ )
+ table.create()
+ # clear out table registry
+ table.deregister()
+
+ try:
+ table = Table(
+ 'override_test', testbase.db,
+ Column('col2', Unicode()),
+ Column('col4', String(30)), autoload=True)
-
+ print repr(table)
+ self.assert_(isinstance(table.c.col1.type, Integer))
+ self.assert_(table.c.col2.type.is_unicode)
+ self.assert_(isinstance(table.c.col4.type, String))
+ finally:
+ table.drop()
+
if __name__ == "__main__":
testbase.main()