Re: [Zope-dev] Reg. persisting data in ZODB via forms

Laurence Rowe <[email protected]>
Newsgroups gmane.comp.web.zope.bluebream,gmane.comp.web.zope.devel
Message-ID <[email protected]>
On 9 June 2011 07:12, Joshua Immanuel <[email protected]> wrote:
> Hello Jonah,
>
> On Wed, 2011-06-08 at 22:25 -0700, Jonah Crawford wrote:
>> Ah yes you do that in the zcml right after you define your object in a
>> class :)
>
> I am not aware of the zcml configuration that can mark a class as
> persistent. If you could explain, it would be helpful.

ZCML is not relevant here.

>> On Jun 8, 2011, at 10:23 PM, Joshua Immanuel wrote:
>> > I was trying to add a non persistent object to the BTreeContainer. I
>> > was of the notion that I don't need to make my object persistent
>> > explicitly, as I am adding it to the persistent btree container. The
>> > add operation was successful but the modify operation on my object
>> > failed to persist.
>> > Making my object persistent solved the issue.
>
> I derived my class from persistent.Persistent in order to make it
> persistent.

Deriving your class from Persistent is normally the right choice.
Storing immutable non-persistent objects such as strings, ints, floats
or tuples of them also works without surprises. Storing mutable
non-persistent objects in the ZODB is considered advanced usage and
you must inform the persistence machinery on any modification. The
best way to do this is to re-assign the non-persistent object to it's
parent persistent object, causing the parent to be marked as modified.

Laurence
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.