]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
"parent track" function needed to be more specific to the parent class
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 10 Jun 2006 19:40:26 +0000 (19:40 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 10 Jun 2006 19:40:26 +0000 (19:40 +0000)
lib/sqlalchemy/attributes.py
test/base/attributes.py

index c285ea50c005e12301f00104b3b767102003b565..07b395fee0de5c5fddfe56ebf3c30d7ac817f74a 100644 (file)
@@ -95,10 +95,10 @@ class ManagedAttribute(object):
     def plain_init(self, *args, **kwargs):
         pass
     def hasparent(self, item):
-        return item.__class__._attribute_manager.attribute_history(item).get('_hasparent_' + self.key)
+        return item.__class__._attribute_manager.attribute_history(item).get(('_hasparent_', self.obj.__class__, self.key))
     def sethasparent(self, item, value):
         if item is not None:
-            item.__class__._attribute_manager.attribute_history(item)['_hasparent_' + self.key] = value
+            item.__class__._attribute_manager.attribute_history(item)[('_hasparent_', self.obj.__class__, self.key)] = value
 
 class ScalarAttribute(ManagedAttribute):
     """Used by AttributeManager to track the history of a scalar attribute
index bff864fa6929d7324602d406af15ec0aecbcdfd2..382e9863efcbd885145646c1061ed03e7874d0f6 100644 (file)
@@ -166,6 +166,31 @@ class AttributesTest(PersistTest):
         assert y.element == 'this is the bar attr'
         assert x.element2 == 'this is the shared attr'
         assert y.element2 == 'this is the shared attr'
+
+    def testparenttrack(self):    
+        class Foo(object):pass
+        class Bar(object):pass
+
+        manager = attributes.AttributeManager()
+
+        manager.register_attribute(Foo, 'element', uselist=False, trackparent=True)
+        manager.register_attribute(Bar, 'element', uselist=False, trackparent=True)
+
+        f1 = Foo()
+        f2 = Foo()
+        b1 = Bar()
+        b2 = Bar()
+
+        f1.element = b1
+        b2.element = f2
+
+        assert manager.get_history(f1, 'element').hasparent(b1)
+        assert not manager.get_history(f1, 'element').hasparent(b2)
+        assert not manager.get_history(f1, 'element').hasparent(f2)
+        assert manager.get_history(b2, 'element').hasparent(f2)
+
+        b2.element = None
+        assert not manager.get_history(b2, 'element').hasparent(f2)
         
 if __name__ == "__main__":
     unittest.main()