Parse-sdk-js: Objects from live queries are not the correct subclass

Created on 4 Nov 2016  路  5Comments  路  Source: parse-community/Parse-SDK-JS

When using LiveQueries I expect the objects I get from when running find or each on the query and the object that the live queries events produces to be of the same class.

But when doing

const MyExtendedClass = Parse.Object.extend('InAppNotification', {
  getType() {
    return 'myType';
  },
}, {});
const query = new ParseQuery(MyExtendedClass);

query.each((object) => {
  // object here is ParseObjectSubclass
  // and I can use object.getType()
});

query.subscribe().on('enter', (object) => {
  // object here is ParseObject
  // and I can't use object.getType()
});

I fiddled around with it a bit and changed so that the default switch statement at https://github.com/ParsePlatform/Parse-SDK-JS/blob/master/src/LiveQueryClient.js#L390

used ParseObject.fromJSON instead like it's done in ParseQuery on https://github.com/ParsePlatform/Parse-SDK-JS/blob/master/src/ParseQuery.js#L288
and it seemed to work as I expected.

I'm not familiar enough with the parse code to know that I'm right, it might be some great reason why you can't use fromJSON at that point that I'm missing or could that be a viable solution?

I'm using Parse 1.9.1

bug

Most helpful comment

So Gyran and I work on the same team currently we have a workaround that looks as follows which seems to work (if someone else has an issue with this)

const jsonObj = objectFromLiveQuery.toJSON();
jsonObj.className = objectFromLiveQuery.className;
const usableObject = Parse.Object.fromJSON(jsonObj));

All 5 comments

So Gyran and I work on the same team currently we have a workaround that looks as follows which seems to work (if someone else has an issue with this)

const jsonObj = objectFromLiveQuery.toJSON();
jsonObj.className = objectFromLiveQuery.className;
const usableObject = Parse.Object.fromJSON(jsonObj));

Cool, thanks for the workaround. It would be great if this bug would be fixed any time soon.

Thanks @mullwaden and @Gyran for the info.
I'm also having the same issue. If I have time I'll try to fix it and submit a pull request. Here is another relevant line for my ref:

@cbess thanks! The issue seems to be isolated and pretty well understood.

The workaround posted above works great :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dblythy picture dblythy  路  4Comments

RaschidJFR picture RaschidJFR  路  7Comments

Simone-cogno picture Simone-cogno  路  7Comments

adrianchifor picture adrianchifor  路  3Comments

marktyers picture marktyers  路  3Comments