summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/mapping
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2006-02-11 15:26:24 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2006-02-11 15:26:24 +0000
commit9323e70225d93971e598ffeeb6cf7c86fa9cbe2e (patch)
tree5d5606ccf4415fd91901e2685b43aed4453079f0 /lib/sqlalchemy/mapping
parentf0e694000cceb34f536706f1096b4d9e4e9840ce (diff)
downloadsqlalchemy-9323e70225d93971e598ffeeb6cf7c86fa9cbe2e.tar.gz
added before_update/after_update
Diffstat (limited to 'lib/sqlalchemy/mapping')
-rw-r--r--lib/sqlalchemy/mapping/mapper.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/sqlalchemy/mapping/mapper.py b/lib/sqlalchemy/mapping/mapper.py
index 9e110b67b..e5e4ab063 100644
--- a/lib/sqlalchemy/mapping/mapper.py
+++ b/lib/sqlalchemy/mapping/mapper.py
@@ -497,7 +497,8 @@ class Mapper(object):
isinsert = not hasattr(obj, "_instance_key")
if isinsert:
self.extension.before_insert(self, obj)
-
+ else:
+ self.extension.before_update(self, obj)
hasdata = False
for col in table.columns:
if self.pks_by_table[table].contains(col):
@@ -536,7 +537,7 @@ class Mapper(object):
if hasdata:
# if none of the attributes changed, dont even
# add the row to be updated.
- update.append(params)
+ update.append((obj, params))
else:
insert.append((obj, params))
if len(update):
@@ -546,7 +547,9 @@ class Mapper(object):
statement = table.update(clause)
rows = 0
for rec in update:
- c = statement.execute(rec)
+ (obj, params) = rec
+ c = statement.execute(params)
+ self.extension.after_update(self, obj)
rows += c.cursor.rowcount
if table.engine.supports_sane_rowcount() and rows != len(update):
raise "ConcurrencyError - updated rowcount %d does not match number of objects updated %d" % (rows, len(update))
@@ -834,6 +837,14 @@ class MapperExtension(object):
this is a good place to set up primary key values and such that arent handled otherwise."""
if self.next is not None:
self.next.before_insert(mapper, instance)
+ def before_update(self, mapper, instance):
+ """called before an object instnace is UPDATED"""
+ if self.next is not None:
+ self.next.before_update(mapper, instance)
+ def after_update(self, mapper, instance):
+ """called after an object instnace is UPDATED"""
+ if self.next is not None:
+ self.next.after_update(mapper, instance)
def after_insert(self, mapper, instance):
"""called after an object instance has been INSERTed"""
if self.next is not None: