diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-05 13:48:52 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-05 13:48:52 -0400 |
| commit | ddb40afc6b5742341c2710a39e06128545752172 (patch) | |
| tree | 1fbf513dcedddb21f234216bdb707d556cb0d1cd /lib/sqlalchemy/orm/dependency.py | |
| parent | 23a49e346bfb757f57fc3778f069ce9ab710fd5e (diff) | |
| parent | cfdc41c75ce2e2228d71733212bbaca0fe17ce35 (diff) | |
| download | sqlalchemy-ddb40afc6b5742341c2710a39e06128545752172.tar.gz | |
branch merge
Diffstat (limited to 'lib/sqlalchemy/orm/dependency.py')
| -rw-r--r-- | lib/sqlalchemy/orm/dependency.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index dec90adfe..04aaa5add 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -548,22 +548,25 @@ class DetectKeySwitch(DependencyProcessor): def _process_key_switches(self, deplist, uowcommit): switchers = set(s for s in deplist if self._pks_changed(uowcommit, s)) if switchers: - # yes, we're doing a linear search right now through the UOW. only - # takes effect when primary key values have actually changed. - # a possible optimization might be to enhance the "hasparents" capability of - # attributes to actually store all parent references, but this introduces - # more complicated attribute accounting. - for s in [elem for elem in uowcommit.session.identity_map.all_states() - if issubclass(elem.class_, self.parent.class_) and - self.key in elem.dict and - elem.dict[self.key] is not None and - attributes.instance_state(elem.dict[self.key]) in switchers - ]: - uowcommit.register_object(s) - sync.populate( - attributes.instance_state(s.dict[self.key]), - self.mapper, s, self.parent, self.prop.synchronize_pairs, - uowcommit, self.passive_updates) + # if primary key values have actually changed somewhere, perform + # a linear search through the UOW in search of a parent. + # possible optimizations here include additional accounting within + # the attribute system, or allowing a one-to-many attr to circumvent + # the need for the search in this direction. + for state in uowcommit.session.identity_map.all_states(): + if not issubclass(state.class_, self.parent.class_): + continue + dict_ = state.dict + related = dict_.get(self.key) + if related is not None: + related_state = attributes.instance_state(dict_[self.key]) + if related_state in switchers: + uowcommit.register_object(state) + sync.populate( + related_state, + self.mapper, state, + self.parent, self.prop.synchronize_pairs, + uowcommit, self.passive_updates) def _pks_changed(self, uowcommit, state): return sync.source_modified(uowcommit, state, self.mapper, self.prop.synchronize_pairs) |
