Skip to content

Commit

Permalink
bugfix: toJSON internal cache ids resulting in wrong data (#3257)
Browse files Browse the repository at this point in the history
* bugfix: using objectSchema.name instead of this.constructor.name

* Changelog: toJSON fix added
  • Loading branch information
steffenagger authored Sep 25, 2020
1 parent 9c53c20 commit c9a3e33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ x.x.x Release notes (yyyy-MM-dd)
* None.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None.
* Fixed an issue with `toJSON` where data from a different object could be serialized. ([#3254](https://github.com/realm/realm-js/issues/3254), since v6.1.0)

### Compatibility
* Realm Object Server: 3.23.1 or later.
Expand Down
6 changes: 3 additions & 3 deletions lib/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ module.exports = function(realmConstructor, context) {
Object.defineProperty(realmConstructor.Object.prototype, "toJSON", {
value: function (_, cache = new Map()) {
// Construct a reference-id of table-name & primaryKey if it exists, or fall back to objectId.
const primaryKey = this.objectSchema().primaryKey;
const id = primaryKey
const { name: schemaName, primaryKey } = this.objectSchema();
const id = primaryKey
? serializedPrimaryKeyValue(this[primaryKey])
: this.constructor.name + this._objectId();
: schemaName + this._objectId();

// Check if current objectId has already processed, to keep object references the same.
const existing = cache.get(id);
Expand Down

0 comments on commit c9a3e33

Please sign in to comment.