summaryrefslogtreecommitdiff
path: root/test/sql/test_selectable.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-02-05 16:58:32 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-02-05 16:58:32 -0500
commit2dbeeff50b7ccc6f47b2816a59f99f051fdabc8c (patch)
treec23ba02c34a7fec923bdddd99ff46b670e30bac2 /test/sql/test_selectable.py
parent28765734826f2619fcfd40f047a5980c3af49010 (diff)
downloadsqlalchemy-2dbeeff50b7ccc6f47b2816a59f99f051fdabc8c.tar.gz
- [bug] Added support for using the .key
of a Column as a string identifier in a result set row. The .key is currently listed as an "alternate" name for a column, and is superseded by the name of a column which has that key value as its regular name. For the next major release of SQLAlchemy we may reverse this precedence so that .key takes precedence, but this is not decided on yet. [ticket:2392]
Diffstat (limited to 'test/sql/test_selectable.py')
-rw-r--r--test/sql/test_selectable.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/sql/test_selectable.py b/test/sql/test_selectable.py
index a4c3ddf40..8f599f1d6 100644
--- a/test/sql/test_selectable.py
+++ b/test/sql/test_selectable.py
@@ -26,6 +26,11 @@ table2 = Table('table2', metadata,
Column('coly', Integer),
)
+keyed = Table('keyed', metadata,
+ Column('x', Integer, key='colx'),
+ Column('y', Integer, key='coly'),
+ Column('z', Integer),
+)
class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL):
__dialect__ = 'default'
@@ -91,6 +96,24 @@ class SelectableTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiled
assert sel3.corresponding_column(l1) is sel3.c.foo
assert sel3.corresponding_column(l2) is sel3.c.bar
+ def test_keyed_gen(self):
+ s = select([keyed])
+ eq_(s.c.colx.key, 'colx')
+
+ # this would change to 'colx'
+ # with #2397
+ eq_(s.c.colx.name, 'x')
+
+ assert s.corresponding_column(keyed.c.colx) is s.c.colx
+ assert s.corresponding_column(keyed.c.coly) is s.c.coly
+ assert s.corresponding_column(keyed.c.z) is s.c.z
+
+ sel2 = s.alias()
+ assert sel2.corresponding_column(keyed.c.colx) is sel2.c.colx
+ assert sel2.corresponding_column(keyed.c.coly) is sel2.c.coly
+ assert sel2.corresponding_column(keyed.c.z) is sel2.c.z
+
+
def test_distance_on_aliases(self):
a1 = table1.alias('a1')
for s in (select([a1, table1], use_labels=True),