diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-08 03:09:18 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-12-08 03:09:18 +0000 |
| commit | d39a15748948904d5d45a3a6ee798b8b799b9311 (patch) | |
| tree | 47fd0f112e62b299cf917710f194f5fa6c2a4d94 /lib | |
| parent | 358bc9db1c86fc26d89ed726305a109af14e2572 (diff) | |
| download | sqlalchemy-d39a15748948904d5d45a3a6ee798b8b799b9311.tar.gz | |
- Session.execute() now locates table- and
mapper-specific binds based on a passed
in expression which is an insert()/update()/delete()
construct. [ticket:1054]
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 16 | ||||
| -rw-r--r-- | lib/sqlalchemy/sql/util.py | 10 |
2 files changed, 15 insertions, 11 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index d3d02ef3f..f171622d4 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -554,13 +554,11 @@ class Session(object): self._mapper_flush_opts = {} if binds is not None: - for mapperortable, value in binds.iteritems(): - if isinstance(mapperortable, type): - mapperortable = _class_mapper(mapperortable).base_mapper - self.__binds[mapperortable] = value - if isinstance(mapperortable, Mapper): - for t in mapperortable._all_tables: - self.__binds[t] = value + for mapperortable, bind in binds.iteritems(): + if isinstance(mapperortable, (type, Mapper)): + self.bind_mapper(mapperortable, bind) + else: + self.bind_table(mapperortable, bind) if not self.autocommit: self.begin() @@ -839,7 +837,7 @@ class Session(object): "a binding.") c_mapper = mapper is not None and _class_to_mapper(mapper) or None - + # manually bound? if self.__binds: if c_mapper: @@ -848,7 +846,7 @@ class Session(object): elif c_mapper.mapped_table in self.__binds: return self.__binds[c_mapper.mapped_table] if clause is not None: - for t in sql_util.find_tables(clause): + for t in sql_util.find_tables(clause, include_crud=True): if t in self.__binds: return self.__binds[t] diff --git a/lib/sqlalchemy/sql/util.py b/lib/sqlalchemy/sql/util.py index 78160ad1e..075d8c7ef 100644 --- a/lib/sqlalchemy/sql/util.py +++ b/lib/sqlalchemy/sql/util.py @@ -47,7 +47,9 @@ def find_join_source(clauses, join_to): return None, None -def find_tables(clause, check_columns=False, include_aliases=False, include_joins=False, include_selects=False): +def find_tables(clause, check_columns=False, + include_aliases=False, include_joins=False, + include_selects=False, include_crud=False): """locate Table objects within the given expression.""" tables = [] @@ -61,7 +63,11 @@ def find_tables(clause, check_columns=False, include_aliases=False, include_join if include_aliases: _visitors['alias'] = tables.append - + + if include_crud: + _visitors['insert'] = _visitors['update'] = \ + _visitors['delete'] = lambda ent: tables.append(ent.table) + if check_columns: def visit_column(column): tables.append(column.table) |
