summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/dependency.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-07-22 01:46:41 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-07-22 01:46:41 -0400
commitca9029ca9830573c4a5618e5dc01347576d50eb4 (patch)
tree680c7622154346c21523c69a0d932a9a91146c24 /lib/sqlalchemy/orm/dependency.py
parent5b91f627a4e5db44c45254f0cb32ac10d0dfabd0 (diff)
downloadsqlalchemy-ca9029ca9830573c4a5618e5dc01347576d50eb4.tar.gz
- Moving an o2m object from one collection to
another, or vice versa changing the referenced object by an m2o, where the foreign key is also a member of the primary key, will now be more carefully checked during flush if the change in value of the foreign key on the "many" side is the result of a change in the primary key of the "one" side, or if the "one" is just a different object. In one case, a cascade-capable DB would have cascaded the value already and we need to look at the "new" PK value to do an UPDATE, in the other we need to continue looking at the "old". We now look at the "old", assuming passive_updates=True, unless we know it was a PK switch that triggered the change. [ticket:1856]
Diffstat (limited to 'lib/sqlalchemy/orm/dependency.py')
-rw-r--r--lib/sqlalchemy/orm/dependency.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py
index baa7af645..e96eed28e 100644
--- a/lib/sqlalchemy/orm/dependency.py
+++ b/lib/sqlalchemy/orm/dependency.py
@@ -468,7 +468,8 @@ class OneToManyDP(DependencyProcessor):
self._synchronize(
state,
child,
- None, True, uowcommit)
+ None, True,
+ uowcommit, False)
if self.post_update and child:
self._post_update(child, uowcommit, [state])
@@ -479,7 +480,8 @@ class OneToManyDP(DependencyProcessor):
self._synchronize(
state,
child,
- None, True, uowcommit)
+ None, True,
+ uowcommit, False)
if self.post_update and child:
self._post_update(child,
uowcommit,
@@ -497,22 +499,25 @@ class OneToManyDP(DependencyProcessor):
passive=True)
if history:
for child in history.added:
- self._synchronize(state, child, None, False, uowcommit)
+ self._synchronize(state, child, None,
+ False, uowcommit, False)
if child is not None and self.post_update:
self._post_update(child, uowcommit, [state])
for child in history.deleted:
if not self.cascade.delete_orphan and \
not self.hasparent(child):
- self._synchronize(state, child, None, True, uowcommit)
+ self._synchronize(state, child, None, True,
+ uowcommit, False)
if self._pks_changed(uowcommit, state):
for child in history.unchanged:
self._synchronize(state, child, None,
- False, uowcommit)
+ False, uowcommit, True)
- def _synchronize(self, state, child, associationrow,
- clearkeys, uowcommit):
+ def _synchronize(self, state, child,
+ associationrow, clearkeys, uowcommit,
+ pks_changed):
source = state
dest = child
if dest is None or \
@@ -524,7 +529,7 @@ class OneToManyDP(DependencyProcessor):
else:
sync.populate(source, self.parent, dest, self.mapper,
self.prop.synchronize_pairs, uowcommit,
- self.passive_updates)
+ self.passive_updates and pks_changed)
def _pks_changed(self, uowcommit, state):
return sync.source_modified(
@@ -713,8 +718,7 @@ class ManyToOneDP(DependencyProcessor):
self.parent,
self.prop.synchronize_pairs,
uowcommit,
- self.passive_updates
- )
+ False)
class DetectKeySwitch(DependencyProcessor):
"""For many-to-one relationships with no one-to-many backref,