From 6a6159500e2d059e23afe8cc72f9e3ffe0611d3b Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 7 Sep 2005 06:26:15 +0000 Subject: [PATCH] moved major awareness of lists, lazyloading, etc. all into the objectstore --- lib/sqlalchemy/objectstore.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/objectstore.py b/lib/sqlalchemy/objectstore.py index b1e454e024..714ea8c292 100644 --- a/lib/sqlalchemy/objectstore.py +++ b/lib/sqlalchemy/objectstore.py @@ -115,10 +115,15 @@ class UnitOfWork: self.attribute_history = weakref.WeakKeyDictionary() def attribute_set(self, obj, key, value): - self.register_attribute(obj, key).setattr(value) + self.register_attribute(obj, key).setattr(value) + obj.__dict__[key] = value + self.register_dirty(obj) + def attribute_deleted(self, obj, key, value): self.register_attribute(obj, key).delattr(value) - + del obj.__dict__[key] + self.register_dirty(obj) + def register_attribute(self, obj, key): try: attributes = self.attribute_history[obj] @@ -128,6 +133,27 @@ class UnitOfWork: return attributes[key] except KeyError: return attributes.setdefault(key, util.PropHistory(obj.__dict__.get(key, None))) + + def register_list_attribute(self, obj, key, data = None, loader = None): + if loader is not None: + obj.__dict__[key] = loader + return + + try: + childlist = obj.__dict__[key] + except KeyError: + childlist = util.HistoryArraySet() + obj.__dict__[key] = childlist + + if callable(childlist): + childlist = childlist() + + if not isinstance(childlist, util.HistoryArraySet): + childlist = util.HistoryArraySet(childlist) + obj.__dict__[key] = childlist + if data is not None and childlist.data != data: + childlist.set_data(data) + return childlist def register_clean(self, obj): self.clean.append(obj) -- 2.47.2