x.clear()
del self.attribute_history(obj)[key]
except KeyError:
- pass
+ try:
+ del obj.__dict__[key]
+ except KeyError:
+ pass
def class_managed(self, class_):
"""returns a dictionary of "history container definitions", which is attached to a
for o in obj:
global_attributes.trigger_history(o, lambda: refresh(o))
+ def expunge(self, *obj):
+ for o in obj:
+ self.uow.expunge(obj)
+
def register_clean(self, obj):
self._bind_to(obj)
self.uow.register_clean(obj)
"""invalidates the data in the given objects and sets them to refresh themselves
the next time they are requested."""
get_session().expire(*obj)
-
+
+def expunge(*obj):
+ get_session().expunge(*obj)
+
def delete(*obj):
"""registers the given objects as to be deleted upon the next commit"""
s = get_session().delete(*obj)
"""returns True if the given key is present in this UnitOfWork's identity map."""
return self.identity_map.has_key(key)
+ def expunge(self, obj):
+ """removes this object completely from the UnitOfWork, including the identity map,
+ and the "new", "dirty" and "deleted" lists."""
+ self._remove_deleted(obj)
+
def _remove_deleted(self, obj):
if hasattr(obj, "_instance_key"):
del self.identity_map[obj._instance_key]
del self.new[obj]
except KeyError:
pass
- self.attributes.commit(obj)
+ #self.attributes.commit(obj)
self.attributes.remove(obj)
def _validate_obj(self, obj):
self.assert_(u is not u2)
def testrefresh(self):
- m = mapper(User, users)
+ m = mapper(User, users, properties={'addresses':relation(mapper(Address, addresses))})
u = m.get(7)
u.user_name = 'foo'
+ a = Address()
+ u.addresses.append(a)
+
+ self.assert_(a in u.addresses)
+
objectstore.refresh(u)
# its refreshed, so not dirty
# username is back to the DB
self.assert_(u.user_name == 'jack')
+ self.assert_(a not in u.addresses)
+
u.user_name = 'foo'
+ u.addresses.append(a)
# now its dirty
self.assert_(u in objectstore.get_session().uow.dirty)
self.assert_(u.user_name == 'foo')
+ self.assert_(a in u.addresses)
objectstore.expire(u)
# expired, but not refreshed yet. still dirty
self.assert_(u in objectstore.get_session().uow.dirty)
# get the attribute, it refreshes
self.assert_(u.user_name == 'jack')
+ self.assert_(a not in u.addresses)
# not dirty anymore
self.assert_(u not in objectstore.get_session().uow.dirty)