]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
removed historyarray test
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Jun 2006 19:02:10 +0000 (19:02 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 16 Jun 2006 19:02:10 +0000 (19:02 +0000)
ForeignKey is more intelligent about locating the parent table it represents, in the case that
its attached to a CompoundSelect column which has multiple "originals", some of which might not be schema.Columns

CHANGES
lib/sqlalchemy/schema.py
test/base/alltests.py
test/base/historyarray.py [deleted file]

diff --git a/CHANGES b/CHANGES
index f23b43ab3569140e05cf6523f8536925115ccb4a..0e7b66f63a2dfca56c6044cd55499c1f42eee79f 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -21,6 +21,7 @@ type conversion happening in the ResultProxy [ticket:207]
 - fixed 'port' attribute of URL to be an integer if present
 - fixed old bug where if a many-to-many table mapped as "secondary"
 had extra columns, delete operations didnt work
+- bugfixes for mapping against UNION queries
 
 0.2.2
 - big improvements to polymorphic inheritance behavior, enabling it
index 368cb2460f2ee0f18d07076fa499482befbc47fd..6878b9c89842c9de80b0b2925ec9419f1bae3262 100644 (file)
@@ -437,15 +437,24 @@ class ForeignKey(SchemaItem):
         # be defined without dependencies
         if self._column is None:
             if isinstance(self._colspec, str):
+                # locate the parent table this foreign key is attached to.  
+                # we use the "original" column which our parent column represents
+                # (its a list of columns/other ColumnElements if the parent table is a UNION)
+                for c in self.parent.orig_set:
+                    if isinstance(c, Column):
+                        parenttable = c.table
+                        break
+                else:
+                    raise exceptions.ArgumentError("Parent column '%s' does not descend from a table-attached Column" % str(self.parent))
                 m = re.match(r"^([\w_-]+)(?:\.([\w_-]+))?(?:\.([\w_-]+))?$", self._colspec)
                 if m is None:
                     raise exceptions.ArgumentError("Invalid foreign key column specification: " + self._colspec)
                 if m.group(3) is None:
                     (tname, colname) = m.group(1, 2)
-                    schema = list(self.parent.orig_set)[0].table.schema
+                    schema = parenttable.schema
                 else:
                     (schema,tname,colname) = m.group(1,2,3)
-                table = Table(tname, list(self.parent.orig_set)[0].metadata, mustexist=True, schema=schema)
+                table = Table(tname, parenttable.metadata, mustexist=True, schema=schema)
                 if colname is None:
                     key = self.parent
                     self._column = table.c[self.parent.key]
index 2ef5b87948b98a612bf2e7cc41a835639e3ad28b..9082375704a9780aec63c858d5d8d5b0be53a083 100644 (file)
@@ -4,7 +4,6 @@ import unittest
 def suite():
     modules_to_test = (
         # core utilities
-        'base.historyarray',
         'base.attributes', 
         'base.dependency',
         )
diff --git a/test/base/historyarray.py b/test/base/historyarray.py
deleted file mode 100644 (file)
index 9fc2704..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-from testbase import PersistTest
-import sqlalchemy.util as util
-import unittest, sys, os
-
-class HistoryArrayTest(PersistTest):
-    def testadd(self):
-        a = util.HistoryArraySet()
-        a.append('hi')
-        self.assert_(a == ['hi'])
-        self.assert_(a.added_items() == ['hi'])
-    
-    def testremove(self):
-        a = util.HistoryArraySet()
-        a.append('hi')
-        a.commit()
-        self.assert_(a == ['hi'])
-        self.assert_(a.added_items() == [])
-        a.remove('hi')
-        self.assert_(a == [])
-        self.assert_(a.deleted_items() == ['hi'])
-        
-    def testremoveadded(self):
-        a = util.HistoryArraySet()
-        a.append('hi')
-        a.remove('hi')
-        self.assert_(a.added_items() == [])
-        self.assert_(a.deleted_items() == [])
-        self.assert_(a == [])
-
-    def testaddedremoved(self):
-        a = util.HistoryArraySet()
-        a.append('hi')
-        a.commit()
-        a.remove('hi')
-        self.assert_(a.deleted_items() == ['hi'])
-        a.append('hi')
-        self.assert_(a.added_items() == [])
-        self.assert_(a.deleted_items() == [])
-        self.assert_(a == ['hi'])
-    
-    def testrollback(self):
-        a = util.HistoryArraySet()
-        a.append('hi')
-        a.append('there')
-        a.append('yo')
-        a.commit()
-        before = repr(a.data)
-        print repr(a.data)
-        a.remove('there')
-        a.append('lala')
-        a.remove('yo')
-        a.append('yo')
-        after = repr(a.data)
-        print repr(a.data)
-        a.rollback()
-        print repr(a.data)
-        self.assert_(before == repr(a.data))
-        
-    def testarray(self):
-        a = util.HistoryArraySet()
-        a.append('hi')
-        a.append('there')
-        self.assert_(a[0] == 'hi' and a[1] == 'there')
-        del a[1]
-        self.assert_(a == ['hi'])
-        a.append('hi')
-        a.append('there')
-        a[3:4] = ['yo', 'hi']
-        self.assert_(a == ['hi', 'there', 'yo'])    
-if __name__ == "__main__":
-    unittest.main()
\ No newline at end of file