diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-01-08 18:11:52 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-01-08 18:11:52 +0000 |
commit | 23b744807599d01e6652a83d82e29da95695c814 (patch) | |
tree | 5cdceb6b7fdbca4f8475460a446a69d6bde08c83 /lib/sqlalchemy/schema.py | |
parent | 4c50fd22ed79425d52f5a05667757c4f83ad5304 (diff) | |
download | sqlalchemy-23b744807599d01e6652a83d82e29da95695c814.tar.gz |
sqlite/postgres reflection will properly add foreign keys
added append_item() method to column to work similarly to table.append_item(), used to
append foreign keys to the column (required in mysql)
appending new foreign keys will properly replace the old one, so explicitly appending
foreign keys to tables will replace those loaded via table reflection (instead of doubling them up)
Diffstat (limited to 'lib/sqlalchemy/schema.py')
-rw-r--r-- | lib/sqlalchemy/schema.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sqlalchemy/schema.py b/lib/sqlalchemy/schema.py index 1d5b504e2..026825737 100644 --- a/lib/sqlalchemy/schema.py +++ b/lib/sqlalchemy/schema.py @@ -238,6 +238,9 @@ class Column(SchemaItem): original = property(lambda s: s._orig or s) engine = property(lambda s: s.table.engine) + def append_item(self, item): + self._init_items(item) + def _set_primary_key(self): if self.primary_key: return @@ -374,6 +377,10 @@ class ForeignKey(SchemaItem): def _set_parent(self, column): self.parent = column + # if a foreign key was already set up for this, replace it with + # this one, including removing from the parent + if self.parent.foreign_key is not None: + self.parent.table.foreign_keys.remove(self.parent.foreign_key) self.parent.foreign_key = self self.parent.table.foreign_keys.append(self) |