]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- polymorphic_union() function respects the "key" of each
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 21 Oct 2008 21:10:51 +0000 (21:10 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 21 Oct 2008 21:10:51 +0000 (21:10 +0000)
Column if they differ from the column's name.

CHANGES
VERSION
lib/sqlalchemy/orm/util.py
test/orm/inheritance/concrete.py

diff --git a/CHANGES b/CHANGES
index 62077572bb34d5fec9ab59e94d3982f0a14a42cb..866f4e7937e46454fac2334da98bae32943e9c9c 100644 (file)
--- 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 cb498ab2c89f41f36e3c6ae234c4e0e844e49e23..76914ddc02f84743f2eb8948b655465598e78425 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.4.8
+0.4.9
index 19e5e59b93280f213d021dfc47b63b8552fb26bf..ff7783c8e5b2cce0d71b128a2e1cfc3a65d793da 100644 (file)
@@ -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):
index 29fa1df6053e713c296563b61ef16c9f0f77bbaa..42e4ee2d6cd8617a2c20e6ed497a0990f1a84135 100644 (file)
@@ -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()