issue(afterFind): Fixes issue when using afterFind with relations (#4752)

* Adds failing test for the issue

* Adds fix for the issue
This commit is contained in:
Florent Vilmart
2018-05-18 09:36:56 -04:00
committed by GitHub
parent c0f86ae1d1
commit fc47f9b84f
2 changed files with 45 additions and 1 deletions

View File

@@ -590,7 +590,18 @@ RestQuery.prototype.runAfterFindTrigger = function() {
}
// Run afterFind trigger and set the new results
return triggers.maybeRunAfterFindTrigger(triggers.Types.afterFind, this.auth, this.className,this.response.results, this.config).then((results) => {
this.response.results = results;
// Ensure we properly set the className back
if (this.redirectClassName) {
this.response.results = results.map((object) => {
if (object instanceof Parse.Object) {
object = object.toJSON();
}
object.className = this.redirectClassName;
return object;
});
} else {
this.response.results = results;
}
});
};