Persisting a dictionary as a object property
Hi all, Ok so I have an object, I have many properties persisting on the object using the wonderful PropertyManager. But I want to persist a dictionary. This isn't an option for the PropertyManager. I added a dictionary into the object just by adding the line: _map = {} But it only persists until I restart Zope... how do I make it last for ever? Thanks.
On Wed, Jul 05, 2000 at 04:52:44PM -0700, Andy McKay wrote:
Ok so I have an object, I have many properties persisting on the object using the wonderful PropertyManager. But I want to persist a dictionary. This isn't an option for the PropertyManager. I added a dictionary into the object just by adding the line: _map = {}
You will have to let the persistance machinery know that you changed the dictionary. A dictionary is a mutable object, and persistance can only track inmutable objects automatically. See the ZODB docs: http://www.zope.org/Documentation/Developer/Models/ZODB/ZODB_Persistent_Obje... (http://www.zope.org/Documentation/Developer/Models/ZODB for the framed set, choose Persitent Objects, then Persitent in the bottom-left frame). You should either treat the dictionary as immutable: data = self._map data.append(foo) self._map = data or set a special flag to let the ZODB know the objetc has changed: self._map.append(foo) self._p_changed = 1 You could also replace the dictionary by a PersitentMapping instance. See above docs for more info. -- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ | ZopeStudio: http://www.zope.org/Products/ZopeStudio -----------------------------------------------------
Thanks that worked like a charm! ----- Original Message ----- From: "Martijn Pieters" <mj@digicool.com> To: "Andy McKay" <AndyM@activestate.com> Cc: <zope@zope.org> Sent: Wednesday, July 05, 2000 5:21 PM Subject: Re: [Zope] Persisting a dictionary as a object property
On Wed, Jul 05, 2000 at 04:52:44PM -0700, Andy McKay wrote:
Ok so I have an object, I have many properties persisting on the object using the wonderful PropertyManager. But I want to persist a dictionary. This isn't an option for the PropertyManager. I added a dictionary into the object just by adding the line: _map = {}
You will have to let the persistance machinery know that you changed the dictionary. A dictionary is a mutable object, and persistance can only track inmutable objects automatically. See the ZODB docs:
http://www.zope.org/Documentation/Developer/Models/ZODB/ZODB_Persistent_Obje cts_Persistent_Doc.html
(http://www.zope.org/Documentation/Developer/Models/ZODB for the framed
set,
choose Persitent Objects, then Persitent in the bottom-left frame).
You should either treat the dictionary as immutable:
data = self._map data.append(foo) self._map = data
or set a special flag to let the ZODB know the objetc has changed:
self._map.append(foo) self._p_changed = 1
You could also replace the dictionary by a PersitentMapping instance. See above docs for more info.
-- Martijn Pieters | Software Engineer mailto:mj@digicool.com | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ | ZopeStudio: http://www.zope.org/Products/ZopeStudio -----------------------------------------------------
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Andy McKay -
Martijn Pieters