Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add old data to the preupdate event #240

Closed

Conversation

davidsf
Copy link

@davidsf davidsf commented Dec 7, 2023

Send the old data of the entity in the preUpdate event.

#239

guardNoAttributes();
guardReadOnly();
mergeAttributesFromCastCache();
fireEvent( "preSave", { entity : this } );
variables._saving = true;
var builder = newQuery();
if ( variables._loaded ) {
fireEvent( "preUpdate", { entity : this } );
fireEvent( "preUpdate", { entity : this, oldData : oldData } );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m going to need tests around this, specifically because I don’t think this is correct. variables._data here will be the data about to be saved.

I think you want variables._originalAttributes which can also be retrieved calling get_originalAttributes() on the entity, which is why nothing extra has been passed in

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, inside the preUpdate() I can access arguments.eventdata.entity.get_originalAttributes() and get the orginal data.

Maybe could be document this in the preUpdate() doc? (I think is a common use of preUpdate to access the original data)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it some more, I think it's okay to pass the original attributes to this method, even though it's also available via the entity.
Passing the current data might be a good option as well. It's a little unwieldy to get the original attributes right now. A method like retrieveOriginalAttributes or retrieveOriginalData would be a good addition as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cborm and hibernate sends the old data to preupdate event. Just for compatibility with others orm I think it's good to have the same behaviour.

@elpete elpete closed this May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants