Mike Bayer avatar Mike Bayer committed 27fec7a

- 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]

Comments (0)

Files changed (3)

     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

lib/sqlalchemy/orm/mapper.py

                     "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
 

test/orm/test_mapper.py

         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)
         mapper(Address, addresses)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.