diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-02 03:50:50 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-01-02 03:50:50 +0000 |
commit | d05a35daf82becc89a9493a178b76cc68363c4ae (patch) | |
tree | 99de001070e2aa9b4963ea5534968583ae979a40 /lib | |
parent | 9cdbf8e8fe0c5b01ca9e38aea49e6a05079402f0 (diff) | |
download | sqlalchemy-d05a35daf82becc89a9493a178b76cc68363c4ae.tar.gz |
- The copy() method on Column now supports uninitialized,
unnamed Column objects. This allows easy creation of
declarative helpers which place common columns on multiple
subclasses (merged from 0.5 with changes).
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sqlalchemy/schema.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 455582c87..ef9137ecd 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -616,8 +616,8 @@ class Column(SchemaItem, expression.ColumnClause): name = kwargs.pop('name', None) type_ = kwargs.pop('type_', None) + args = list(args) if args: - args = list(args) if isinstance(args[0], basestring): if name is not None: raise exc.ArgumentError( @@ -794,10 +794,13 @@ class Column(SchemaItem, expression.ColumnClause): This is used in ``Table.tometadata``. """ + args = [c.copy(**kw) for c in self.constraints] + if self.table is None: + args += [c.copy(**kw) for c in self.foreign_keys] + return Column( - self.name, - self.type, - self.default, + name=self.name, + type_=self.type, key = self.key, primary_key = self.primary_key, nullable = self.nullable, @@ -808,7 +811,8 @@ class Column(SchemaItem, expression.ColumnClause): server_default=self.server_default, onupdate=self.onupdate, server_onupdate=self.server_onupdate, - *[c.copy(**kw) for c in self.constraints]) + *args + ) def _make_proxy(self, selectable, name=None): """Create a *proxy* for this column. @@ -925,7 +929,6 @@ class ForeignKey(SchemaItem): def copy(self, schema=None): """Produce a copy of this ForeignKey object.""" - return ForeignKey( self._get_colspec(schema=schema), use_alter=self.use_alter, @@ -1054,7 +1057,6 @@ class ForeignKey(SchemaItem): return raise exc.InvalidRequestError("This ForeignKey already has a parent !") self.parent = column - self.parent.foreign_keys.add(self) self.parent._on_table_attach(self._set_table) |