c._set_root(root)
def append(self, node):
- if isinstance(node, str):
+ if isinstance(node, basestring):
node = TreeNode(node)
node._set_root(self.root)
self.children.set(node)
else:
if isnew or selectcontext.populate_existing:
key = mapper.identity_key_from_primary_key(instance.parent_id)
- parentnode = selectcontext.identity_map[key]
+ parentnode = selectcontext.session.identity_map[key]
parentnode.children.set(instance)
return False
def fire_append_event(self, state, value, initiator):
if self.key not in state.committed_state and self.key in state.dict:
state.committed_state[self.key] = self.copy(state.dict[self.key])
-
+
state.modified = True
if self.trackparent and value is not None:
original = state.committed_state.get(attr.key, NEVER_SET)
if hasattr(attr, 'get_collection'):
+ current = attr.get_collection(state, current)
if original is NO_VALUE:
return (list(current), [], [])
elif original is NEVER_SET:
return ([], list(current), [])
else:
- collection = util.OrderedIdentitySet(attr.get_collection(state, current))
+ collection = util.OrderedIdentitySet(current)
s = util.OrderedIdentitySet(original)
return (list(collection.difference(s)), list(collection.intersection(s)), list(s.difference(collection)))
else:
f._state.commit(['someattr'])
self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], [old], []))
+ def test_dict_collections(self):
+ class Foo(fixtures.Base):
+ pass
+ class Bar(fixtures.Base):
+ pass
+
+ from sqlalchemy.orm.collections import attribute_mapped_collection
+
+ attributes.register_class(Foo)
+ attributes.register_attribute(Foo, 'someattr', uselist=True, useobject=True, typecallable=attribute_mapped_collection('name'))
+
+ hi = Bar(name='hi')
+ there = Bar(name='there')
+ old = Bar(name='old')
+ new = Bar(name='new')
+
+ f = Foo()
+ self.assertEquals(attributes.get_history(f._state, 'someattr'), ([], [], []))
+
+ f.someattr['hi'] = hi
+ self.assertEquals(attributes.get_history(f._state, 'someattr'), ([hi], [], []))
+
+ f.someattr['there'] = there
+ self.assertEquals(tuple([set(x) for x in attributes.get_history(f._state, 'someattr')]), (set([hi, there]), set([]), set([])))
+
+ f._state.commit(['someattr'])
+ self.assertEquals(tuple([set(x) for x in attributes.get_history(f._state, 'someattr')]), (set([]), set([hi, there]), set([])))
+
+
+
def test_object_collections_mutate(self):
class Foo(fixtures.Base):
pass