Persistence triggering
When appending to a list in Zope In a persistent class I cannot just do: self.list.append(item) As it will not trigger the persistence mechanism. I can treat it like an imutable, but that is rather tedious: _list = self.list _list.append(item) self.list = _list But can I also do? self.list = self.list + [item] Regards Max M Max M. W. Rasmussen, Denmark. New Media Director private: maxmcorp@worldonline.dk work: maxm@normik.dk ----------------------------------------------------- Specialization is for insects. - Robert A. Heinlein
But can I also do?
self.list = self.list + [item]
Yes... this works because you're treating it immutably. Although this is likely much slower than an .append because the interpreter needs to make a copy of self.list before tacking on your item. You can also do: self.list.append(item) self._p_changed = 1 This explicitly tells the ZODB to include the object represented by self in the current transaction.
From: Chris McDonough [mailto:chrism@digicool.com]
You can also do:
self.list.append(item) self._p_changed = 1
This explicitly tells the ZODB to include the object represented by self in the current transaction.
Yes but I have avoided using it as I wanted to make a class that is "Pure" Python so I can edit and debug it without zope, and then write a "small" wrapper class to make it a product. Somehow I had gotten it into my head that I could not do that with, self._p_changed = 1 because it isn't defined in my class but inherited. Funny how you can get your head the wrong way around things. Naturally it will have no effect on my own class if I set that value. So I guess I will use that. Thanks for the help. Regards Max M
participants (2)
-
Chris McDonough -
Max M