summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-07-19 20:25:09 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-07-19 20:25:09 +0000
commitf4415c21c57dd2caa8638b4e7f9670a9f563e88c (patch)
treeba79a86f89879dfa2fce81959ed2e06b64b47cc5 /test
parentd2513a54eb62f5e217eb738ecacb3b2058472228 (diff)
downloadsqlalchemy-f4415c21c57dd2caa8638b4e7f9670a9f563e88c.tar.gz
mapper compilation work ongoing, someday it'll work....moved
around the initialization of MapperProperty objects to be after all mappers are created to better handle circular compilations. do_init() method is called on all properties now which are more aware of their "inherited" status if so. eager loads explicitly disallowed on self-referential relationships, or relationships to an inheriting mapper (which is also self-referential)
Diffstat (limited to 'test')
-rw-r--r--test/orm/cycles.py15
-rw-r--r--test/orm/polymorph.py26
2 files changed, 39 insertions, 2 deletions
diff --git a/test/orm/cycles.py b/test/orm/cycles.py
index fb051f47a..8a4161364 100644
--- a/test/orm/cycles.py
+++ b/test/orm/cycles.py
@@ -79,7 +79,22 @@ class SelfReferentialTest(AssertMixin):
sess.delete(a)
sess.flush()
+ def testeagerassertion(self):
+ """test that an eager self-referential relationship raises an error."""
+ class C1(Tester):
+ pass
+ class C2(Tester):
+ pass
+
+ m1 = mapper(C1, t1, properties = {
+ 'c1s' : relation(C1, lazy=False),
+ })
+ try:
+ m1.compile()
+ assert False
+ except exceptions.ArgumentError:
+ assert True
class BiDirectionalOneToManyTest(AssertMixin):
"""tests two mappers with a one-to-many relation to each other."""
def setUpAll(self):
diff --git a/test/orm/polymorph.py b/test/orm/polymorph.py
index 34b7ddde2..410af94d8 100644
--- a/test/orm/polymorph.py
+++ b/test/orm/polymorph.py
@@ -105,8 +105,7 @@ class MultipleTableTest(testbase.PersistTest):
print session.query(Person).select()
def testcompile2(self):
- """this test fails. mapper compilation completely doesnt work for this right now and likely
- needs to be rewritten again."""
+ """test that a mapper can reference a property whose mapper inherits from this one."""
person_join = polymorphic_union( {
'engineer':people.join(engineers),
'manager':people.join(managers),
@@ -124,6 +123,29 @@ class MultipleTableTest(testbase.PersistTest):
#person_mapper.compile()
class_mapper(Manager).compile()
+
+ def testcompile3(self):
+ """test that a mapper referencing an inheriting mapper in a self-referential relationship does
+ not allow an eager load to be set up."""
+ person_join = polymorphic_union( {
+ 'engineer':people.join(engineers),
+ 'manager':people.join(managers),
+ 'person':people.select(people.c.type=='person'),
+ }, None, 'pjoin')
+
+ person_mapper = mapper(Person, people, select_table=person_join, polymorphic_on=person_join.c.type,
+ polymorphic_identity='person',
+ properties = dict(managers = relation(Manager, lazy=False))
+ )
+
+ mapper(Engineer, engineers, inherits=person_mapper, polymorphic_identity='engineer')
+ mapper(Manager, managers, inherits=person_mapper, polymorphic_identity='manager')
+
+ try:
+ class_mapper(Manager).compile()
+ assert False
+ except exceptions.ArgumentError:
+ assert True
def do_test(self, include_base=False, lazy_relation=True, redefine_colprop=False):
"""tests the polymorph.py example, with several options: