diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-08 19:30:00 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-10-08 19:30:00 +0000 |
commit | ef77cfa61b6a894202495d460b055de6fea9eed6 (patch) | |
tree | 3e7ae1e4621bfc790f882babe392cae2fcc94119 /lib/sqlalchemy/sql_util.py | |
parent | b0ffcbc264f6a92ba5092e5d785a2dbfe418c307 (diff) | |
download | sqlalchemy-ef77cfa61b6a894202495d460b055de6fea9eed6.tar.gz |
- mapper.save_obj() now functions across all mappers in its polymorphic
series, UOWTask calls mapper appropriately in this manner
- polymorphic mappers (i.e. using inheritance) now produces INSERT
statements in order of tables across all inherited classes
[ticket:321]
Diffstat (limited to 'lib/sqlalchemy/sql_util.py')
-rw-r--r-- | lib/sqlalchemy/sql_util.py | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/sqlalchemy/sql_util.py b/lib/sqlalchemy/sql_util.py index 4015fd244..94caade68 100644 --- a/lib/sqlalchemy/sql_util.py +++ b/lib/sqlalchemy/sql_util.py @@ -6,8 +6,18 @@ import sqlalchemy.util as util class TableCollection(object): - def __init__(self): - self.tables = [] + def __init__(self, tables=None): + self.tables = tables or [] + def __len__(self): + return len(self.tables) + def __getitem__(self, i): + return self.tables[i] + def __iter__(self): + return iter(self.tables) + def __contains__(self, obj): + return obj in self.tables + def __add__(self, obj): + return self.tables + list(obj) def add(self, table): self.tables.append(table) if hasattr(self, '_sorted'): @@ -29,10 +39,11 @@ class TableCollection(object): import sqlalchemy.orm.topological tuples = [] class TVisitor(schema.SchemaVisitor): - def visit_foreign_key(self, fkey): + def visit_foreign_key(_self, fkey): parent_table = fkey.column.table - child_table = fkey.parent.table - tuples.append( ( parent_table, child_table ) ) + if parent_table in self: + child_table = fkey.parent.table + tuples.append( ( parent_table, child_table ) ) vis = TVisitor() for table in self.tables: table.accept_schema_visitor(vis) @@ -57,16 +68,6 @@ class TableFinder(TableCollection, sql.ClauseVisitor): table.accept_visitor(self) def visit_table(self, table): self.tables.append(table) - def __len__(self): - return len(self.tables) - def __getitem__(self, i): - return self.tables[i] - def __iter__(self): - return iter(self.tables) - def __contains__(self, obj): - return obj in self.tables - def __add__(self, obj): - return self.tables + list(obj) def visit_column(self, column): if self.check_columns: column.table.accept_visitor(self) |