diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-15 00:07:06 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-15 00:07:06 +0000 |
| commit | 7e5e985c0e17a2d300f9aa8633c3610db600f2e2 (patch) | |
| tree | 553780288c3fc75697d1558187c85f09a9cb42ed /lib/sqlalchemy/schema.py | |
| parent | 6b40f50b87a03172d77abf0e50f42b565f416645 (diff) | |
| download | sqlalchemy-7e5e985c0e17a2d300f9aa8633c3610db600f2e2.tar.gz | |
- ForeignKey(Constraint) supports "use_alter=True", to create/drop a foreign key
via ALTER. this allows circular foreign key relationships to be set up.
Diffstat (limited to 'lib/sqlalchemy/schema.py')
| -rw-r--r-- | lib/sqlalchemy/schema.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 5728d7c37..88d52f075 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -491,7 +491,7 @@ class ForeignKey(SchemaItem): One or more ForeignKey objects are used within a ForeignKeyConstraint object which represents the table-level constraint definition.""" - def __init__(self, column, constraint=None, use_alter=False): + def __init__(self, column, constraint=None, use_alter=False, name=None): """Construct a new ForeignKey object. "column" can be a schema.Column object representing the relationship, @@ -507,6 +507,7 @@ class ForeignKey(SchemaItem): self._column = None self.constraint = constraint self.use_alter = use_alter + self.name = name def __repr__(self): return "ForeignKey(%s)" % repr(self._get_colspec()) @@ -575,7 +576,7 @@ class ForeignKey(SchemaItem): self.parent = column if self.constraint is None and isinstance(self.parent.table, Table): - self.constraint = ForeignKeyConstraint([],[], use_alter=self.use_alter) + self.constraint = ForeignKeyConstraint([],[], use_alter=self.use_alter, name=self.name) self.parent.table.append_constraint(self.constraint) self.constraint._append_fk(self) @@ -699,6 +700,8 @@ class ForeignKeyConstraint(Constraint): self.elements = util.Set() self.onupdate = onupdate self.ondelete = ondelete + if self.name is None and use_alter: + raise exceptions.ArgumentError("Alterable ForeignKey/ForeignKeyConstraint requires a name") self.use_alter = use_alter def _set_parent(self, table): self.table = table |
