[Helma-user] Adding objects to generic object reference in onPersist()

Anton Pirker helma at gmiatlich.net
Wed Sep 5 12:58:10 CEST 2007


Hi List!

I have a Prototype 'Change'. This is some sort of changelog for 
HopObjects. I add it to Objects via a generic object reference (as 
described at [1])

Everythink works fine if i add the Change the normal way to my object, like:

   var venue = new Venue("Supervenue");
   var ch = new Change(u);
   venue.changes.add(ch);



But i want to add the Changelog automatically. So i wrote a onPersist() 
in HopObject.

So everytime when i store something i do the following:

function onPersist() {

   //check if we have a collection
   //to store the changes to
   if(this.changes) {
     //create the change and add it.
     var ch = new Change(u);	
     this.changes.add(ch);
   }
}


But the Change is not stored into the Database and I do not get an error 
message.


I think it is because onPersist is called right before the object is 
stored. So when a create a 'Change' object and add it to a 
'changes'-collection of this in onPersist this does not have an finale 
id and so the 'Change'-Object does not know who his parent is.

I also wrote a little demo-app to explain it a little better.

Does anyone know how i can achieve this, or i what i am doing wrong?

Thanks in advance!
Anton

[1] http://helma.org/bugs/show_bug.cgi?id=516
-------------- next part --------------
A non-text attachment was scrubbed...
Name: onpersist.zip
Type: application/octet-stream
Size: 2266 bytes
Desc: not available
Url : http://helma.org/pipermail/helma-user/attachments/20070905/36d23953/attachment.obj 


More information about the Helma-user mailing list