]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- moved extension class init around so query() is available
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 7 Aug 2007 17:29:03 +0000 (17:29 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 7 Aug 2007 17:29:03 +0000 (17:29 +0000)
lib/sqlalchemy/orm/mapper.py
test/orm/session.py

index fed7d2c928ba31e26bf58af8396b93562cec3ad4..807811ba25968fe164056c6fc8eaf52dfd5c03d8 100644 (file)
@@ -294,7 +294,9 @@ class Mapper(object):
                 extlist.add(ext_class)
             else:
                 extlist.add(ext_class())
-
+            # local MapperExtensions have already instrumented the class
+            extlist[-1].instrument_class(self, self.class_)
+            
         extension = self.extension
         if extension is not None:
             for ext_obj in util.to_list(extension):
@@ -303,8 +305,6 @@ class Mapper(object):
         self.extension = ExtensionCarrier()
         for ext in extlist:
             self.extension.append(ext)
-
-        self.extension.instrument_class(self, self.class_)
         
     def _compile_inheritance(self):
         """Determine if this Mapper inherits from another mapper, and
@@ -709,6 +709,9 @@ class Mapper(object):
         finally:
             _COMPILE_MUTEX.release()
 
+        for ext in util.to_list(self.extension, []):
+            ext.instrument_class(self, self.class_)
+
         if self.entity_name is None:
             self.class_.c = self.c
 
index 0b56b84d4fe7c3d68ec3a940e1150cb2313a2564..23968686944ab897ea324bf2f8693d38bf871740 100644 (file)
@@ -485,6 +485,12 @@ class ScopedSessionTest(PersistTest):
         sso = SomeOtherObject.query().first()
         assert SomeObject.query.filter_by(id=1).one().options[0].id == sso.id
 
+    def test_query_compiles(self):
+        class Foo(object):
+            pass
+        Session.mapper(Foo, table2)
+        assert hasattr(Foo, 'query')
+        
     def test_validating_constructor(self):
         s2 = SomeObject(someid=12)
         s3 = SomeOtherObject(someid=123, bogus=345)