[Helma-user] Adding objects to generic object reference in onPersist()
Anton Pirker
helma at gmiatlich.net
Fri Sep 7 10:04:39 CEST 2007
Just a little update!
I patched my local Helma and made me my own afterPersist()-Call and
tried the same thing. Same result.
When i was debugging my Application with the debugger shipped with Helma
i recognized, that there is some bug in the watch-window.
I was watching "this" and when the code jumped into a constructor() the
"this" didn't change. So if i am in Venue-Code "this" is "[HopObject
Venue]". When the code jumps into the constructor() of Change, "this"
remained "[HopObject Venue]"! When i use app.log() to debug "this"
changes to "[HopObject Change]".
But back to my problem: I don't have a clue how to solve the Problem.
(Of course i could solve it somehow with database Triggers, but i would
prefer to do it with Helma)
Does no one has a clue or a hint for me? Every help is appreciated.
I wonder if no one has dome something like this before..
Cheers,
Anton
Anton Pirker schrieb:
> 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
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Helma-user mailing list
> Helma-user at helma.org
> http://helma.org/mailman/listinfo/helma-user
More information about the Helma-user
mailing list