From 47fac5873b02ec08f2a608d8c0cf8867996c795d Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 3 Feb 2006 01:15:06 +0000 Subject: [PATCH] attempting to get MTOBackrefExtension to handle many-to-one, one-to-one equally --- lib/sqlalchemy/attributes.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/attributes.py b/lib/sqlalchemy/attributes.py index f2480918d4..87b09507f9 100644 --- a/lib/sqlalchemy/attributes.py +++ b/lib/sqlalchemy/attributes.py @@ -89,6 +89,10 @@ class PropHistory(object): self.obj.__dict__[self.key] = None if self.extension is not None: self.extension.set(self.obj, None, self.orig) + def append(self, obj): + self.setattr(obj) + def remove(self, obj): + self.delattr() def rollback(self): if self.orig is not PropHistory.NONE: self.obj.__dict__[self.key] = self.orig @@ -242,9 +246,12 @@ class MTOBackrefExtension(AttributeExtension): self.key = key def set(self, obj, child, oldchild): if oldchild is not None: - getattr(oldchild, self.key).remove(obj) + prop = oldchild.__class__._attribute_manager.get_history(oldchild, self.key) + prop.remove(obj) if child is not None: - getattr(child, self.key).append(obj) + prop = child.__class__._attribute_manager.get_history(child, self.key) + prop.append(obj) + class AttributeManager(object): """maintains a set of per-attribute history container objects for a set of objects.""" def __init__(self): -- 2.47.2