]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
columns can be specified to override those from autoload=True
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 4 Feb 2006 23:41:07 +0000 (23:41 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 4 Feb 2006 23:41:07 +0000 (23:41 +0000)
lib/sqlalchemy/schema.py
test/engines.py

index 6679c8b0575718d8705785d9aae2d0045a73730f..a5e6e0777f8b888ba02e1b1f52b282dbf140aad9 100644 (file)
@@ -81,14 +81,16 @@ class TableSingleton(type):
         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
 
         
@@ -98,7 +100,7 @@ class Table(SchemaItem):
     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:
         
@@ -138,7 +140,6 @@ class Table(SchemaItem):
         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)
index 10aa380bac498b8b2a09c1ca0b9425a3ea1ed0e0..25bfb3eac05bc2cea07328b72480b3b7f1ae5fd1 100644 (file)
@@ -117,8 +117,30 @@ class EngineTest(PersistTest):
         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()