]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- A mixin can now specify a column that overrides
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Oct 2010 20:54:39 +0000 (16:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Oct 2010 20:54:39 +0000 (16:54 -0400)
a column of the same name associated with a superclass.
Thanks to Oystein Haaland.

CHANGES
lib/sqlalchemy/ext/declarative.py
test/ext/test_declarative.py

diff --git a/CHANGES b/CHANGES
index 9eb89b07bf9649f358cd46e0634c54754b5b8bae..97a3cceb9b1c16b5cc4c5459049ab612519f83d8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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
index debfdfe5712908e8acec71a9576471575b419cfb..dd2df63d30265021025c1caf29f1fd97552349d9 100755 (executable)
@@ -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()
index 0a6b17e27a64f4a3bd93e6df38ef2904cf280fdb..72e2edf30e9a8a9f336ee98263185447f3feea02 100644 (file)
@@ -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: