summaryrefslogtreecommitdiff
path: root/test/orm/inheritance/test_basic.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-05-12 12:47:09 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-05-12 12:47:09 -0400
commit9826ba73a6a614a92be7104474428dde40c2d773 (patch)
tree64f6f06570fffe2a8322529e2ca5c3bc765a1ca1 /test/orm/inheritance/test_basic.py
parent2101cf7f405e43465cc33a854df43a859bc8e3ab (diff)
downloadsqlalchemy-9826ba73a6a614a92be7104474428dde40c2d773.tar.gz
- polymorphic_union() gets a "cast_nulls" option,
disables the usage of CAST when it renders the labeled NULL columns. [ticket:1502] - polymorphic_union() renders the columns in their original table order, as according to the first table/selectable in the list of polymorphic unions in which they appear. (which is itself an unordered mapping unless you pass an OrderedDict).
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r--test/orm/inheritance/test_basic.py58
1 files changed, 57 insertions, 1 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index ee408373a..ce1d8028d 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -5,7 +5,7 @@ from sqlalchemy import exc as sa_exc, util
from sqlalchemy.orm import *
from sqlalchemy.orm import exc as orm_exc, attributes
from test.lib.assertsql import AllOf, CompiledSQL
-
+from sqlalchemy.sql import table, column
from test.lib import testing, engines
from test.lib import fixtures
from test.orm import _fixtures
@@ -1816,4 +1816,60 @@ class DeleteOrphanTest(fixtures.MappedTest):
sess.add(s1)
assert_raises(sa_exc.DBAPIError, sess.flush)
+class PolymorphicUnionTest(fixtures.TestBase, testing.AssertsCompiledSQL):
+ __dialect__ = 'default'
+
+ def _fixture(self):
+ t1 = table('t1', column('c1', Integer),
+ column('c2', Integer),
+ column('c3', Integer))
+ t2 = table('t2', column('c1', Integer), column('c2', Integer),
+ column('c3', Integer),
+ column('c4', Integer))
+ t3 = table('t3', column('c1', Integer),
+ column('c3', Integer),
+ column('c5', Integer))
+ return t1, t2, t3
+
+ def test_type_col_present(self):
+ t1, t2, t3 = self._fixture()
+ self.assert_compile(
+ polymorphic_union(
+ util.OrderedDict([("a", t1), ("b", t2), ("c", t3)]),
+ 'q1'
+ ),
+ "SELECT t1.c1, t1.c2, t1.c3, CAST(NULL AS INTEGER) AS c4, "
+ "CAST(NULL AS INTEGER) AS c5, 'a' AS q1 FROM t1 UNION ALL "
+ "SELECT t2.c1, t2.c2, t2.c3, t2.c4, CAST(NULL AS INTEGER) AS c5, "
+ "'b' AS q1 FROM t2 UNION ALL SELECT t3.c1, "
+ "CAST(NULL AS INTEGER) AS c2, t3.c3, CAST(NULL AS INTEGER) AS c4, "
+ "t3.c5, 'c' AS q1 FROM t3"
+ )
+
+ def test_type_col_non_present(self):
+ t1, t2, t3 = self._fixture()
+ self.assert_compile(
+ polymorphic_union(
+ util.OrderedDict([("a", t1), ("b", t2), ("c", t3)]),
+ None
+ ),
+ "SELECT t1.c1, t1.c2, t1.c3, CAST(NULL AS INTEGER) AS c4, "
+ "CAST(NULL AS INTEGER) AS c5 FROM t1 UNION ALL SELECT t2.c1, "
+ "t2.c2, t2.c3, t2.c4, CAST(NULL AS INTEGER) AS c5 FROM t2 "
+ "UNION ALL SELECT t3.c1, CAST(NULL AS INTEGER) AS c2, t3.c3, "
+ "CAST(NULL AS INTEGER) AS c4, t3.c5 FROM t3"
+ )
+
+ def test_no_cast_null(self):
+ t1, t2, t3 = self._fixture()
+ self.assert_compile(
+ polymorphic_union(
+ util.OrderedDict([("a", t1), ("b", t2), ("c", t3)]),
+ 'q1', cast_nulls=False
+ ),
+ "SELECT t1.c1, t1.c2, t1.c3, NULL AS c4, NULL AS c5, 'a' AS q1 "
+ "FROM t1 UNION ALL SELECT t2.c1, t2.c2, t2.c3, t2.c4, NULL AS c5, "
+ "'b' AS q1 FROM t2 UNION ALL SELECT t3.c1, NULL AS c2, t3.c3, "
+ "NULL AS c4, t3.c5, 'c' AS q1 FROM t3"
+ )