]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- ForeignKey to a table in a schema thats not the default schema
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Jul 2007 21:18:46 +0000 (21:18 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Jul 2007 21:18:46 +0000 (21:18 +0000)
requires the schema to be explicit; i.e. ForeignKey('alt_schema.users.id')
- the fix in "schema" above fixes postgres reflection of foreign keys from an
alt-schema table to a public schema table

CHANGES
lib/sqlalchemy/schema.py
test/dialect/postgres.py

diff --git a/CHANGES b/CHANGES
index 3f486511d114919c887fdc6d1a0515cf85884aaf..5aa8734340a37d5e81c3bf9c03f4ca194eb155fa 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,8 @@
       trip over synonyms (and others) that are named after the column's actual
       "key" (since, column_prefix means "dont use the key").
 - sql
+    - ForeignKey to a table in a schema thats not the default schema
+      requires the schema to be explicit; i.e. ForeignKey('alt_schema.users.id')
     - MetaData can now be constructed with an engine or url as the first
       argument, just like BoundMetaData
     - BoundMetaData is now deprecated, and MetaData is a direct substitute.
@@ -82,6 +84,8 @@
     - added support for reflection of domains [ticket:570]
     - types which are missing during reflection resolve to Null type
       instead of raising an error
+    - the fix in "schema" above fixes reflection of foreign keys from an
+      alt-schema table to a public schema table
 - sqlite
     - sqlite better handles datetime/date/time objects mixed and matched
       with various Date/Time/DateTime columns
index d01677b6974b977acd1eda5d83f48782d7afdc5d..eb7eb8c1d9ded517bf55667d38c9b446fcdf10e9 100644 (file)
@@ -701,7 +701,7 @@ class ForeignKey(SchemaItem):
                     raise exceptions.ArgumentError("Invalid foreign key column specification: " + self._colspec)
                 if m.group(3) is None:
                     (tname, colname) = m.group(1, 2)
-                    schema = parenttable.schema
+                    schema = None
                 else:
                     (schema,tname,colname) = m.group(1,2,3)
                 table = Table(tname, parenttable.metadata, mustexist=True, schema=schema)
index 8a69f24536792b4852df79cb3e3eae31ff5289ac..8d62625c9a890026ea0f7c099670d916d9f4e21a 100644 (file)
@@ -120,6 +120,50 @@ class MiscTest(AssertMixin):
         finally:
             meta1.drop_all()
 
+    @testbase.supported('postgres')
+    def test_schema_reflection_2(self):
+        meta1 = MetaData(testbase.db)
+        subject = Table("subject", meta1,
+                        Column("id", Integer, primary_key=True),
+                        )
+
+        referer = Table("referer", meta1,
+                        Column("id", Integer, primary_key=True),
+                        Column("ref", Integer, ForeignKey('subject.id')),
+                        schema="alt_schema")
+        meta1.create_all()
+        try:
+            meta2 = MetaData(testbase.db)
+            subject = Table("subject", meta2, autoload=True)
+            referer = Table("referer", meta2, schema="alt_schema", autoload=True)
+            print str(subject.join(referer).onclause)
+            self.assert_((subject.c.id==referer.c.ref).compare(subject.join(referer).onclause))
+        finally:
+            meta1.drop_all()
+            
+    @testbase.supported('postgres')
+    def test_schema_reflection_3(self):
+        meta1 = MetaData(testbase.db)
+        subject = Table("subject", meta1,
+                        Column("id", Integer, primary_key=True),
+                        schema='alt_schema_2'
+                        )
+
+        referer = Table("referer", meta1,
+                        Column("id", Integer, primary_key=True),
+                        Column("ref", Integer, ForeignKey('alt_schema_2.subject.id')),
+                        schema="alt_schema")
+
+        meta1.create_all()
+        try:
+            meta2 = MetaData(testbase.db)
+            subject = Table("subject", meta2, autoload=True, schema="alt_schema_2")
+            referer = Table("referer", meta2, schema="alt_schema", autoload=True)
+            print str(subject.join(referer).onclause)
+            self.assert_((subject.c.id==referer.c.ref).compare(subject.join(referer).onclause))
+        finally:
+            meta1.drop_all()
+        
     @testbase.supported('postgres')
     def test_preexecute_passivedefault(self):
         """test that when we get a primary key column back