diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-10-21 16:54:39 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-10-21 16:54:39 -0400 |
commit | c5579f77e26e1449f82888c4a95466a77642130d (patch) | |
tree | 917d2c8578b353a85f89ed9793a0235e1dcb15e6 | |
parent | ee345b055c2c0c44a6cee4f14f70ebb5e4725aab (diff) | |
download | sqlalchemy-c5579f77e26e1449f82888c4a95466a77642130d.tar.gz |
- A mixin can now specify a column that overrides
a column of the same name associated with a superclass.
Thanks to Oystein Haaland.
-rw-r--r-- | CHANGES | 6 | ||||
-rwxr-xr-x | lib/sqlalchemy/ext/declarative.py | 2 | ||||
-rw-r--r-- | test/ext/test_declarative.py | 21 |
3 files changed, 27 insertions, 2 deletions
@@ -192,7 +192,11 @@ CHANGES inheritance scheme where the attribute name is different than that of the column. [ticket:1930], [ticket:1931]. - + + - A mixin can now specify a column that overrides + a column of the same name associated with a superclass. + Thanks to Oystein Haaland. + - engine - Fixed a regression in 0.6.4 whereby the change that diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index debfdfe57..dd2df63d3 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -1015,7 +1015,7 @@ def _as_declarative(cls, classname, dict_): if name not in dict_ and not ( '__table__' in dict_ and (obj.name or name) in dict_['__table__'].c - ): + ) and name not in potential_columns: potential_columns[name] = \ column_copies[obj] = \ obj.copy() diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 0a6b17e27..72e2edf30 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -2170,7 +2170,28 @@ class DeclarativeMixinTest(DeclarativeTestBase): eq_(obj.name, 'testing') eq_(obj.foo(), 'bar1') eq_(obj.baz, 'fu') + + def test_mixin_overrides(self): + """test a mixin that overrides a column on a superclass.""" + + class MixinA(object): + foo = Column(String(50)) + + class MixinB(MixinA): + foo = Column(Integer) + class MyModelA(Base, MixinA): + __tablename__ = 'testa' + id = Column(Integer, primary_key=True) + + class MyModelB(Base, MixinB): + __tablename__ = 'testb' + id = Column(Integer, primary_key=True) + + eq_(MyModelA.__table__.c.foo.type.__class__, String) + eq_(MyModelB.__table__.c.foo.type.__class__, Integer) + + def test_not_allowed(self): class MyMixin: |