summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-10-21 21:10:51 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-10-21 21:10:51 +0000
commitadc72de6a4fe2547b015ccc41c6b956137290925 (patch)
tree9ff89fd4a59bac96d9626fdbccbde62823c95d6f
parentbfc90aa6c69511fc71aa6079ecc86e9315b042b7 (diff)
downloadsqlalchemy-adc72de6a4fe2547b015ccc41c6b956137290925.tar.gz
- polymorphic_union() function respects the "key" of each
Column if they differ from the column's name.
-rw-r--r--CHANGES8
-rw-r--r--VERSION2
-rw-r--r--lib/sqlalchemy/orm/util.py6
-rw-r--r--test/orm/inheritance/concrete.py47
4 files changed, 58 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index 62077572b..866f4e793 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,12 @@
=======
CHANGES
=======
+0.4.9
+=====
+- orm
+ - polymorphic_union() function respects the "key" of each
+ Column if they differ from the column's name.
+
0.4.8
=====
- orm
@@ -15,7 +21,7 @@ CHANGES
- Added label() method to InstrumentedAttribute
to establish forwards compatibility with 0.5.
-
+
- sql
- column.in_(someselect) can now be used as
a columns-clause expression without the subquery
diff --git a/VERSION b/VERSION
index cb498ab2c..76914ddc0 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.4.8
+0.4.9
diff --git a/lib/sqlalchemy/orm/util.py b/lib/sqlalchemy/orm/util.py
index 19e5e59b9..ff7783c8e 100644
--- a/lib/sqlalchemy/orm/util.py
+++ b/lib/sqlalchemy/orm/util.py
@@ -57,9 +57,9 @@ def polymorphic_union(table_map, typecolname, aliasname='p_union'):
m = {}
for c in table.c:
- colnames.add(c.name)
- m[c.name] = c
- types[c.name] = c.type
+ colnames.add(c.key)
+ m[c.key] = c
+ types[c.key] = c.type
colnamemaps[table] = m
def col(name, table):
diff --git a/test/orm/inheritance/concrete.py b/test/orm/inheritance/concrete.py
index 29fa1df60..42e4ee2d6 100644
--- a/test/orm/inheritance/concrete.py
+++ b/test/orm/inheritance/concrete.py
@@ -188,7 +188,54 @@ class ConcreteTest(ORMTest):
assert set([repr(x) for x in c2.employees]) == set(["Engineer Kurt knows how to hack", "Manager Tom knows how to manage things"])
self.assert_sql_count(testing.db, go, 1)
+class ColKeysTest(ORMTest):
+ def define_tables(self, metadata):
+ global offices_table, refugees_table
+ refugees_table = Table('refugee', metadata,
+ Column('refugee_fid', Integer, primary_key=True),
+ Column('refugee_name', Unicode(30), key='name'))
+
+ offices_table = Table('office', metadata,
+ Column('office_fid', Integer, primary_key=True),
+ Column('office_name', Unicode(30), key='name'))
+
+ def insert_data(self):
+ refugees_table.insert().execute(
+ dict(refugee_fid=1, name=u"refugee1"),
+ dict(refugee_fid=2, name=u"refugee2")
+ )
+ offices_table.insert().execute(
+ dict(office_fid=1, name=u"office1"),
+ dict(office_fid=2, name=u"office2")
+ )
+
+ def test_keys(self):
+ pjoin = polymorphic_union({
+ 'refugee': refugees_table,
+ 'office': offices_table
+ }, 'type', 'pjoin')
+ class Location(object):
+ pass
+
+ class Refugee(Location):
+ pass
+
+ class Office(Location):
+ pass
+
+ location_mapper = mapper(Location, pjoin, polymorphic_on=pjoin.c.type,
+ polymorphic_identity='location')
+ office_mapper = mapper(Office, offices_table, inherits=location_mapper,
+ concrete=True, polymorphic_identity='office')
+ refugee_mapper = mapper(Refugee, refugees_table, inherits=location_mapper,
+ concrete=True, polymorphic_identity='refugee')
+
+ sess = create_session()
+ assert sess.query(Refugee).get(1).name == "refugee1"
+ assert sess.query(Refugee).get(2).name == "refugee2"
+ assert sess.query(Office).get(1).name == "office1"
+ assert sess.query(Office).get(2).name == "office2"
if __name__ == '__main__':
testenv.main()