diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-12-09 11:12:41 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-12-09 11:12:41 -0500 |
commit | 33ddb48da48af3425a71543da8bab7911455cfee (patch) | |
tree | d8bb9d4c0302f8786adbfe2223d1f9389ea4d7fc /test/orm/inheritance/test_basic.py | |
parent | d1cc7e7517da26521639fb22826d6e91e51c928e (diff) | |
download | sqlalchemy-33ddb48da48af3425a71543da8bab7911455cfee.tar.gz |
- Standalone expressions in polymorphic_on
propagate to single-table inheritance
subclasses so that they are used in the
WHERE /JOIN clause to limit rows to that
subclass as is the usual behavior.
- make sure implicit map to polymorphic_on expr
handles creating a label(). Use an explicit name
here as _sa_polymorphic_on makes more sense when
poking around in _props.
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r-- | test/orm/inheritance/test_basic.py | 52 |
1 files changed, 50 insertions, 2 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index c9aa5fc9b..dab2d5639 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -186,19 +186,62 @@ class PolymorphicOnNotLocalTest(fixtures.MappedTest): self._roundtrip() - def test_polymorphic_on_expr_implicit_map(self): + def test_polymorphic_on_expr_implicit_map_no_label_joined(self): t2, t1 = self.tables.t2, self.tables.t1 Parent, Child = self.classes.Parent, self.classes.Child expr = case([ (t1.c.x=="p", "parent"), (t1.c.x=="c", "child"), - ],else_ = t1.c.x).label("foo") + ],else_ = t1.c.x) + mapper(Parent, t1, polymorphic_identity="parent", + polymorphic_on=expr) + mapper(Child, t2, inherits=Parent, polymorphic_identity="child") + + self._roundtrip() + + def test_polymorphic_on_expr_implicit_map_w_label_joined(self): + t2, t1 = self.tables.t2, self.tables.t1 + Parent, Child = self.classes.Parent, self.classes.Child + expr = case([ + (t1.c.x=="p", "parent"), + (t1.c.x=="c", "child"), + ],else_ = t1.c.x).label(None) mapper(Parent, t1, polymorphic_identity="parent", polymorphic_on=expr) mapper(Child, t2, inherits=Parent, polymorphic_identity="child") self._roundtrip() + def test_polymorphic_on_expr_implicit_map_no_label_single(self): + """test that single_table_criterion is propagated + with a standalone expr""" + t2, t1 = self.tables.t2, self.tables.t1 + Parent, Child = self.classes.Parent, self.classes.Child + expr = case([ + (t1.c.x=="p", "parent"), + (t1.c.x=="c", "child"), + ],else_ = t1.c.x) + mapper(Parent, t1, polymorphic_identity="parent", + polymorphic_on=expr) + mapper(Child, inherits=Parent, polymorphic_identity="child") + + self._roundtrip() + + def test_polymorphic_on_expr_implicit_map_w_label_single(self): + """test that single_table_criterion is propagated + with a standalone expr""" + t2, t1 = self.tables.t2, self.tables.t1 + Parent, Child = self.classes.Parent, self.classes.Child + expr = case([ + (t1.c.x=="p", "parent"), + (t1.c.x=="c", "child"), + ],else_ = t1.c.x).label(None) + mapper(Parent, t1, polymorphic_identity="parent", + polymorphic_on=expr) + mapper(Child, inherits=Parent, polymorphic_identity="child") + + self._roundtrip() + def test_polymorphic_on_column_prop(self): t2, t1 = self.tables.t2, self.tables.t1 Parent, Child = self.classes.Parent, self.classes.Child @@ -269,6 +312,11 @@ class PolymorphicOnNotLocalTest(fixtures.MappedTest): [Parent, Child, Parent] ) + eq_( + [type(t) for t in s.query(Child).all()], + [Child] + ) + class FalseDiscriminatorTest(fixtures.MappedTest): @classmethod |