]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix to MapperExtension create_instance so that entity_name properly associated
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Dec 2006 20:52:32 +0000 (20:52 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 19 Dec 2006 20:52:32 +0000 (20:52 +0000)
with new instance

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

diff --git a/CHANGES b/CHANGES
index 7b44e4c85c45fe71d546dd278a38140cc6a53e54..dff9e71c93ed0a348483aece99dcec000cd9224c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,6 @@
 - added "BIGSERIAL" support for postgres table with PGBigInteger/autoincrement
+- fix to MapperExtension create_instance so that entity_name properly associated
+with new instance
 
 0.3.3
 - string-based FROM clauses fixed, i.e. select(..., from_obj=["sometext"])
index 78fd3a1cc2f3e388944e9ad63b8d2fc4303672fd..46ef5f60fa3ffdeba344094d4823c8a45d00960f 100644 (file)
@@ -1187,6 +1187,8 @@ class Mapper(object):
             instance = self.extension.create_instance(self, context, row, self.class_)
             if instance is EXT_PASS:
                 instance = self._create_instance(context.session)
+            else:
+                instance._entity_name = self.entity_name
             if self.__should_log_debug:
                 self.__log_debug("_instance(): created new instance %s identity %s" % (mapperutil.instance_str(instance), str(identitykey)))
             context.identity_map[identitykey] = instance
@@ -1398,7 +1400,8 @@ def has_identity(object):
     return hasattr(object, '_instance_key')
     
 def has_mapper(object):
-    """returns True if the given object has a mapper association"""
+    """return True if the given object has had a mapper association set up, either through loading,
+    or via insertion in a session."""
     return hasattr(object, '_entity_name')
 
 
index 533faed6def99c516b4b2c5a7517a5902833962d..4bcaf07cb4614a57c7ff9ab8a987499e89437388 100644 (file)
@@ -760,7 +760,20 @@ class LazyTest(MapperSuperTest):
         self.assert_result([u], User,
             {'user_id' : 7, 'addresses' : (Address, [{'address_id' : 1}])},
             )
-
+    
+    def testcreateinstance(self):
+        class Ext(MapperExtension):
+            def create_instance(self, *args, **kwargs):
+                return User()
+        m = mapper(Address, addresses)
+        m = mapper(User, users, extension=Ext(), properties = dict(
+            addresses = relation(Address, lazy=True),
+        ))
+        
+        q = create_session().query(m)
+        l = q.select();
+        self.assert_result(l, User, *user_address_result)
+        
     def testorderby(self):
         m = mapper(Address, addresses)