From bcc4f63a0790cd95a32dd334230656867e9a6b9e Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 16 Jun 2006 19:02:10 +0000 Subject: [PATCH] removed historyarray test 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 | 1 + lib/sqlalchemy/schema.py | 13 +++++-- test/base/alltests.py | 1 - test/base/historyarray.py | 71 --------------------------------------- 4 files changed, 12 insertions(+), 74 deletions(-) delete mode 100644 test/base/historyarray.py diff --git a/CHANGES b/CHANGES index f23b43ab35..0e7b66f63a 100644 --- 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 diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 368cb2460f..6878b9c898 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -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] diff --git a/test/base/alltests.py b/test/base/alltests.py index 2ef5b87948..9082375704 100644 --- a/test/base/alltests.py +++ b/test/base/alltests.py @@ -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 index 9fc270432b..0000000000 --- a/test/base/historyarray.py +++ /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 -- 2.47.2