diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-06-15 15:27:39 +0000 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-06-15 15:27:39 +0000 |
| commit | f9468e8759d3c8401f71cd6f4b4e9ffeadf4c817 (patch) | |
| tree | dcf6934c513e481ad67c38d0ab650bb773418c3e /lib/sqlalchemy | |
| parent | 3f8bfe517c2cb9687fa3d32443d762dfdbf0ae87 (diff) | |
| download | sqlalchemy-f9468e8759d3c8401f71cd6f4b4e9ffeadf4c817.tar.gz | |
if an item attached to a parent is found to be already in the session, then the "save-update" cascade operation doesnt take place. currently this prevents unncessessary cascading due to backref events, which was a massive speed hit.
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/unitofwork.py | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index bf97f3b79..5c222edee 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -46,16 +46,11 @@ class UOWListElement(attributes.ListAttribute): sess = object_session(obj) if sess is not None: sess._register_changed(obj) - if self.cascade is not None: - if not isdelete: - if self.cascade.save_update: - # cascade the save_update operation onto the child object, - # relative to the mapper handling the parent object - # TODO: easier way to do this ? - mapper = object_mapper(obj) - prop = mapper.props[self.key] - ename = prop.mapper.entity_name - sess.save_or_update(item, entity_name=ename) + if self.cascade is not None and not isdelete and self.cascade.save_update and item not in sess: + mapper = object_mapper(obj) + prop = mapper.props[self.key] + ename = prop.mapper.entity_name + sess.save_or_update(item, entity_name=ename) def append(self, item, _mapper_nohistory = False): if _mapper_nohistory: self.append_nohistory(item) @@ -71,15 +66,11 @@ class UOWScalarElement(attributes.ScalarAttribute): sess = object_session(obj) if sess is not None: sess._register_changed(obj) - if newvalue is not None and self.cascade is not None: - if self.cascade.save_update: - # cascade the save_update operation onto the child object, - # relative to the mapper handling the parent object - # TODO: easier way to do this ? - mapper = object_mapper(obj) - prop = mapper.props[self.key] - ename = prop.mapper.entity_name - sess.save_or_update(newvalue, entity_name=ename) + if newvalue is not None and self.cascade is not None and self.cascade.save_update and newvalue not in sess: + mapper = object_mapper(obj) + prop = mapper.props[self.key] + ename = prop.mapper.entity_name + sess.save_or_update(newvalue, entity_name=ename) class UOWAttributeManager(attributes.AttributeManager): """overrides AttributeManager to provide unit-of-work "dirty" hooks when scalar attribues are modified, plus factory methods for UOWProperrty/UOWListElement.""" |
