summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-07 17:29:03 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-07 17:29:03 +0000
commiteff13aa146ef23c05dd57c9020a722f1ca311452 (patch)
tree0f638fe82b3a066e383a126581f95165a2b622aa
parentc7ee47e545316272ff0864e46c5afbd338df9cb1 (diff)
downloadsqlalchemy-eff13aa146ef23c05dd57c9020a722f1ca311452.tar.gz
- moved extension class init around so query() is available
-rw-r--r--lib/sqlalchemy/orm/mapper.py9
-rw-r--r--test/orm/session.py6
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index fed7d2c92..807811ba2 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -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
diff --git a/test/orm/session.py b/test/orm/session.py
index 0b56b84d4..239686869 100644
--- a/test/orm/session.py
+++ b/test/orm/session.py
@@ -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)