]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- a non_primary mapper will inherit the _identity_class
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Apr 2011 16:51:50 +0000 (12:51 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Apr 2011 16:51:50 +0000 (12:51 -0400)
of the primary mapper.  This so that a non_primary
established against a class that's normally in an
inheritance mapping will produce results that are
identity-map compatible with that of the primary
mapper [ticket:2151]

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/test_mapper.py

diff --git a/CHANGES b/CHANGES
index 4fa2fe702f0f3ef0543a06f825132705513cf15c..c632465a29c1afb68cc5d830c21e8db5820ab2e9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -10,6 +10,13 @@ CHANGES
     invalid, this condition now raises a deprecation warning.
     [ticket:2144]
 
+  - a non_primary mapper will inherit the _identity_class
+    of the primary mapper.  This so that a non_primary
+    established against a class that's normally in an
+    inheritance mapping will produce results that are 
+    identity-map compatible with that of the primary
+    mapper [ticket:2151]
+
 - sql
   - Fixed bug whereby if FetchedValue was passed
     to column server_onupdate, it would not
index 1f5e30f8187fc392b808712fcb01d9003bf8a3ef..07be0b746e52cc7ba811a79d0e0c43e9c9fd4a50 100644 (file)
@@ -376,6 +376,7 @@ class Mapper(object):
                     "a primary mapper first before setting up a non primary "
                     "Mapper." % self.class_)
             self.class_manager = manager
+            self._identity_class = manager.mapper._identity_class
             _mapper_registry[self] = True
             return
 
index d25fb2826b39ac836e2ecf6e0903b471466e7fa0..4c82bc50b79bd8b547f850382c399b1644432e31 100644 (file)
@@ -450,6 +450,19 @@ class MapperTest(_fixtures.FixtureTest):
         assert n1.children[0] is n1._children[0] is n2
         eq_(str(Node.parent == n2), ":param_1 = nodes.parent_id")
 
+    @testing.resolve_artifact_names
+    def test_non_primary_identity_class(self):
+        class AddressUser(User):
+            pass
+        m1 = mapper(User, users, polymorphic_identity='user')
+        m2 = mapper(AddressUser, addresses, inherits=User, polymorphic_identity='address')
+        m3 = mapper(AddressUser, addresses, non_primary=True)
+        assert m3._identity_class is m2._identity_class
+        eq_(
+            m2.identity_key_from_instance(AddressUser()),
+            m3.identity_key_from_instance(AddressUser())
+        )
+
     @testing.resolve_artifact_names
     def test_illegal_non_primary(self):
         mapper(User, users)