]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed/covered case when using a False value as a
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Mar 2008 03:02:28 +0000 (03:02 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 12 Mar 2008 03:02:28 +0000 (03:02 +0000)
polymorphic discriminator

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/inheritance/basic.py

diff --git a/CHANGES b/CHANGES
index 2c9120be5bd0fe24fbd7c2ec1f00f54ecf5ecba4..d9b9b7d39165c506a4dfd20093012a502f25a090 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -8,7 +8,10 @@ CHANGES
     - when attributes are expired on a pending instance, an 
       error will not be raised when the "refresh" action 
       is triggered and returns no result
-    
+      
+    - fixed/covered case when using a False value as a 
+      polymorphic discriminator
+      
 0.4.4
 ------
 - sql
index b7ed313950f0b3f2085775bb2ab9cefbc6a63506..011dc4d55a96c96fa1b0f6e4ef073a9ecf9171b7 100644 (file)
@@ -337,7 +337,7 @@ class Mapper(object):
             else:
                 self._synchronizer = None
                 self.mapped_table = self.local_table
-            if self.polymorphic_identity:
+            if self.polymorphic_identity is not None:
                 self.inherits.polymorphic_map[self.polymorphic_identity] = self
                 if self.polymorphic_on is None:
                     for mapper in self.iterate_to_root():
index 3f3bf4bdb760c2cee4ebb3bf98abd7a7809fefd6..699d3e7186fa5d391fc7914645792fa5ee62dc1c 100644 (file)
@@ -64,6 +64,22 @@ class O2MTest(ORMTest):
         self.assert_(compare == result)
         self.assert_(l[0].parent_foo.data == 'foo #1' and l[1].parent_foo.data == 'foo #1')
 
+class FalseDiscriminatorTest(ORMTest):
+    def define_tables(self, metadata):
+        global t1
+        t1 = Table('t1', metadata, Column('id', Integer, primary_key=True), Column('type', Integer, nullable=False))
+        
+    def test_false_discriminator(self):
+        class Foo(object):pass
+        class Bar(Foo):pass
+        mapper(Foo, t1, polymorphic_on=t1.c.type, polymorphic_identity=1)
+        mapper(Bar, inherits=Foo, polymorphic_identity=0)
+        sess = create_session()
+        f1 = Bar()
+        sess.save(f1)
+        sess.flush()
+        assert f1.type == 0
+        
 class CascadeTest(ORMTest):
     """that cascades on polymorphic relations continue
     cascading along the path of the instance's mapper, not