From: Mike Bayer Date: Wed, 12 Mar 2008 03:02:28 +0000 (+0000) Subject: - fixed/covered case when using a False value as a X-Git-Tag: rel_0_4_5~100 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=100338f43619e5f4c3f7d5ad241847e6ceae4011;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - fixed/covered case when using a False value as a polymorphic discriminator --- diff --git a/CHANGES b/CHANGES index 2c9120be5b..d9b9b7d391 100644 --- 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 diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index b7ed313950..011dc4d55a 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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(): diff --git a/test/orm/inheritance/basic.py b/test/orm/inheritance/basic.py index 3f3bf4bdb7..699d3e7186 100644 --- a/test/orm/inheritance/basic.py +++ b/test/orm/inheritance/basic.py @@ -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