diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-01-05 04:00:21 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-01-05 04:00:21 +0000 |
| commit | 6ea7729bbb7f21cd890a4e125f6482978efcb86d (patch) | |
| tree | 9d092cb1fb61717c9034cfbc95fa151ebbaf86f3 | |
| parent | c55454e536071f966393aa66f85d2993be296a8a (diff) | |
| download | sqlalchemy-6ea7729bbb7f21cd890a4e125f6482978efcb86d.tar.gz | |
added support for foreign keys to work across schemas
| -rw-r--r-- | lib/sqlalchemy/schema.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index c726bd2f0..c5054cd50 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -315,7 +315,8 @@ class ForeignKey(SchemaItem): def __init__(self, column): """Constructs a new ForeignKey object. "column" can be a schema.Column object representing the relationship, or just its string name given as - "tablename.columnname".""" + "tablename.columnname". schema can be specified as + "schemaname.tablename.columnname" """ self._colspec = column self._column = None @@ -341,11 +342,16 @@ class ForeignKey(SchemaItem): # be defined without dependencies if self._column is None: if isinstance(self._colspec, str): - m = re.match(r"([\w_-]+)(?:\.([\w_-]+))?", self._colspec) + m = re.match(r"^([\w_-]+)(?:\.([\w_-]+))?(?:\.([\w_-]+))?$", self._colspec) if m is None: - raise "Invalid foreign key column specification: " + self._colspec - (tname, colname) = m.group(1, 2) - table = Table(tname, self.parent.engine, mustexist = True) + raise ValueError("Invalid foreign key column specification: " + self._colspec) + if m.group(3) is None: + (tname, colname) = m.group(1, 2) + # default to containing table's schema + schema = self.parent.table.schema + else: + (schema,tname,colname) = m.group(1,2,3) + table = Table(tname, self.parent.engine, mustexist=True, schema=schema) if colname is None: key = self.parent self._column = table.c[self.parent.key] |
