summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-11 12:42:06 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-11 12:42:06 -0500
commit19de4da70f714a1918ed1370f9a4ac589f20b7de (patch)
tree6a6fdf8aea3699cd398f28a2f0044d813ea7bfc4
parent86df449c2b724341f3d3f322ad71252b287e1f12 (diff)
downloadsqlalchemy-19de4da70f714a1918ed1370f9a4ac589f20b7de.tar.gz
- the copy() method of Column now copies over uninitialized
"on table attach" events. Helps with the new declarative "mixin" capability.
-rw-r--r--CHANGES4
-rw-r--r--lib/sqlalchemy/schema.py7
-rw-r--r--test/engine/test_metadata.py15
3 files changed, 23 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index fe9f32396..00cb3384e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -188,6 +188,10 @@ CHANGES
coercing a returned floating point value into a string
on its way to Decimal - this allows accuracy to function
on SQLite, MySQL. [ticket:1717]
+
+ - the copy() method of Column now copies over uninitialized
+ "on table attach" events. Helps with the new declarative
+ "mixin" capability.
- engines
- Added an optional C extension to speed up the sql layer by
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py
index 08386059d..8ffb68a4e 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -813,7 +813,7 @@ class Column(SchemaItem, expression.ColumnClause):
[c.copy(**kw) for c in self.constraints] + \
[c.copy(**kw) for c in self.foreign_keys if not c.constraint]
- return Column(
+ c = Column(
name=self.name,
type_=self.type,
key = self.key,
@@ -828,7 +828,10 @@ class Column(SchemaItem, expression.ColumnClause):
server_onupdate=self.server_onupdate,
*args
)
-
+ if hasattr(self, '_table_events'):
+ c._table_events = list(self._table_events)
+ return c
+
def _make_proxy(self, selectable, name=None):
"""Create a *proxy* for this column.
diff --git a/test/engine/test_metadata.py b/test/engine/test_metadata.py
index 0d2cb7775..3a1a19cd4 100644
--- a/test/engine/test_metadata.py
+++ b/test/engine/test_metadata.py
@@ -54,7 +54,20 @@ class MetaDataTest(TestBase, ComparesTables):
for a1, a2 in zip(col.foreign_keys, c2.foreign_keys):
assert a1 is not a2
eq_(a2._colspec, 'bat.blah')
-
+
+ def test_uninitialized_column_copy_events(self):
+ msgs = []
+ def write(t, c):
+ msgs.append("attach %s.%s" % (t.name, c.name))
+ c1 = Column('foo', String())
+ c1._on_table_attach(write)
+ m = MetaData()
+ for i in xrange(3):
+ cx = c1.copy()
+ t = Table('foo%d' % i, m, cx)
+ eq_(msgs, ['attach foo0.foo', 'attach foo1.foo', 'attach foo2.foo'])
+
+
def test_dupe_tables(self):
metadata = MetaData()
t1 = Table('table1', metadata, Column('col1', Integer, primary_key=True),