Project

General

Profile

Dbo: PostUpdate, PreUpdate, etc.

Added by Alexander Theißen about 10 years ago

Is there are events or something I can hook functions to. For example to update a timestamp field whenever an object gets updated.


Replies (2)

RE: Dbo: PostUpdate, PreUpdate, etc. - Added by Eivind Midtgård about 10 years ago

I wonder if you could just add code in the persist method (I'm just guessing here!):

    template<class Action>
    void persist(Action& a)
    {
        std::cout << "The name was updated or read at " << timestamp() << "\n";
        Wt::Dbo::field(a, m_name,         "name");
    }

You would probably need to find out what actions are possible so that you update your timestamp only when writing, perhaps a Wt::Dbo::SaveBaseAction:

Regards,

Eivind

RE: Dbo: PostUpdate, PreUpdate, etc. - Added by Koen Deforche about 10 years ago

Hey,

Indeed, you can probably do that from within the persist method (if that's an acceptible solution to you). You can filter out the relevant action by investigaing the action.getsValue() and action.setsValue() methods:

  • a.getsValue() saving to the database
  • a.setsValue() reading from the database

Regards,

koen

    (1-2/2)