Closed Cloudtrackers closed 4 years ago
I believe this is proper functionality. Saving an object clears dirty keys. If you want to check dirty keys try beforeSave
.
I believe this is proper functionality. Saving an object clears dirty keys. If you want to check dirty keys try
beforeSave
.
it's not working in afterSave hook. in afterSave, In the case of Updating the value, dirty keys always returns empty array.
Can you write a failing test here. This will help us replicate your issue.
Can you write a failing test here. This will help us replicate your issue.
Parse.Cloud.afterSave("Profile", async (req) => { let token = { sessionToken: req.user.getSessionToken() }; console.log(req.object.dirtyKeys()); });
just try this code in an sample code. dirtyKeys always returns empty array.
As @dplewis already pointed out, after saving an object, there are no dirty keys. A key is only dirty after its value has been modified and before its new value has been saved to the database.
object.set(key, "newValue");
--> object is dirtyobject.save();
--> request to save new value to databasebeforeSave
trigger is called --> object is dirtyafterSave
trigger is called --> object is not dirtyI'm closing this as it does not seem to be a Parse Server issue.
For help with Parse Server, here are some resources you can try:
Feel free to comment if you have any questions and we can re-open this issue.
New Issue Checklist
Issue Description
Server: 4.3.0 Database: Mongo 4.0,
Steps to reproduce
Parse.Cloud.afterSave("Profile", async (req) => { let token = { sessionToken: req.user.getSessionToken() }; console.log("-> ", req.original, req.object.dirty("isActive")); });
Actual Outcome
req.object.dirty("keyname"); always return false than actual result.
Expected Outcome
if the particular key attribute value is changed, 'req.object.dirty("keyname");' should be true else false.
Environment
Server: 4.3.0 Database: Mongo 4.0,
Server
Database
Client
Logs