]> 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:54:15 +0000 (12:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Apr 2011 16:54:15 +0000 (12:54 -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] (also in 0.6.8)

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

diff --git a/CHANGES b/CHANGES
index cc96f18b5045d56da1655176493fcf6f77596c3d..69994c84b9e4ba0b1241e0eb2b9119ef41b330f4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,13 @@ CHANGES
   - horizontal shard query should use execution
     options per connection as per [ticket:2131]
 
+  - 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] (also in 0.6.8)
+
 - sql
   - Some improvements to error handling inside
     of the execute procedure to ensure auto-close
index c91003fd9d380cfa17fb5f39a1ff0c214bc7f926..53f8af0b4e67d9cfe2c22f6dba095d0a5dc233dd 100644 (file)
@@ -589,6 +589,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 7d154de629caa3c818722a3b72cbcc0fb271d426..9929886ab3f90294d311c3a166a50c7e1d704abc 100644 (file)
@@ -474,6 +474,21 @@ class MapperTest(_fixtures.FixtureTest):
         assert n1.children[0] is n1._children[0] is n2
         eq_(str(Node.parent == n2), ":param_1 = nodes.parent_id")
 
+    def test_non_primary_identity_class(self):
+        User = self.classes.User
+        users, addresses = self.tables.users, self.tables.addresses
+        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())
+        )
+
     def test_illegal_non_primary(self):
         users, Address, addresses, User = (self.tables.users,
                                 self.classes.Address,