On 2/15/06, Paul Winkler <[EMAIL PROTECTED]> wrote: > On Wed, Feb 15, 2006 at 01:21:14PM +0000, Peter Bengtsson wrote: > > I understand the mutation stuff and I always do it like this in zope2 > > (I'm a complete beginner in the zope3 world eager to learn): > > > > def updatesometing(self): > > #self.numbers['Peter'] = "0779 123 456" > > numbers = self.numbers > > numbers['Peter'] = "0779 123 456" > > self.numbers = numbers > > > > But in zope2 land, if I derive from Persistent it magically saves ALL > > attributes defined in __init__ assuming that I post-write to them > > correct as shown above. > > That hasn't changed in zope 3. This is just standard ZODB behavior. > setattr will cause a save on commit regardless of the type of > the value. If you read Jeff's reply again carefully, he said as much. > > PersistentList and PersistentDict are not new, either. > They've been used in Zope 2 projects for ages. > > There are still exactly three ways to get sub-object mutations to > persist: > > 1) Set the "dirty bit" by hand, e.g.: > > self.alist.append(1) > self._p_changed = 1 > > 2) Re-assign the attribute, e.g.: > > alist = self.alist > alist.append(1) > self.alist = alist > > 3) Using a persistent sub-object, e.g. a PersistentList instance: > > self.alist.append(1) >
Now I get it! Sorry for being slow and thanks for explaining. So by using PersistentList it just means that you can use: self.alist.append(1) in your code. The attribute, self.alist, is still saved even without PersistentList but it just means you have to be careful when writing to it. Cool! -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users