Skip to content

after select query object overide #371

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

Closed
udaykushwah opened this issue Nov 4, 2016 · 5 comments · Fixed by #409
Closed

after select query object overide #371

udaykushwah opened this issue Nov 4, 2016 · 5 comments · Fixed by #409

Comments

@udaykushwah
Copy link

Hi Parse Team,

I am facing problem with parse open source js sdk 1.9.2 .when i apply find query without select.i got full object from parse. after that i make query on same class with select and specified key server return selected object with specified key. but my previous data/object override.
can you any tell me this is open issue with parse open source js sdk.

@andrewimm
Copy link
Contributor

This is how the SDK works by default. All objects pointing to the same server data are backed by the same data.

If you have one ParseObject with the id 'abc', and another ParseObject with the id 'abc', saving changes to one will be reflected in both.

let A = new Parse.Object();
A.id = 'abc';

let B = new Parse.Object();
B.id = 'abc';

A.save({count: 12}).then(() => {
  assert(A.get('count') === 12);
  // B is synchronized to the latest server data
  assert(B.get('count');

  // This also works for atomic operations, where it is especially useful, since
  // the result comes directly from the server
  A.increment('count');
  return A.save();
}).then(() => {
  assert(A.get('count') === 13);
  assert(B.get('count') === 13);
});

This is because objects should represent the last known state of truth from the server. If we know for a fact that a new value was saved to the server, we can safely update the other objects backed by that.

This is designed for client side applications, since they usually want to not need to implement logic to keep every part of the UI in sync.

If you really want to have objects be completely separate, you can fun the following when your program begins:

Parse.Object.disableSingleInstance();

@udaykushwah
Copy link
Author

Thanks for response @andrewimm

@dstarke
Copy link
Contributor

dstarke commented Feb 10, 2017

@andrewimm I'm surprised that this is not considered a bug. When a query is issued with a select, we know that the object returned will only be part of the truth from the server. The current implementation, on retrieving the results of a query with a select, erases all the information in the shared object except the fields included in the select, which are updated. That's not the best possible estimate of the state of truth on the server.

This behavior can also force a client to retrieve much more information than necessary in some situations, just to make sure that the object remains consistent for use elsewhere.

Ideally, for a query with a select, the cached object should only be updated or erased for the fields involved in the query. An easier mostly correct solution would be to not override the object when retrieving it from a query with a select.

I've tested out a change to ParseQuery.find() that does the latter, and it seems to work much more as I would expect, and I would be happy to submit it as a pull request.

@andrewimm
Copy link
Contributor

@dstarke you're right, what you describe should be the correct behavior, I may have misunderstood the full context of the original question. I'd welcome a PR to handle this.

@dstarke
Copy link
Contributor

dstarke commented Feb 11, 2017

@andrewimm I added the PR. It ended up being a little more complicated than my earlier test. The complication comes almost entirely from handling select fields that reference sub-objects using dot notation.

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 a pull request may close this issue.

3 participants