Skip to content

Cannot get back the full object from the relational field after saving an object #251

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
carmenlau opened this issue Apr 6, 2016 · 7 comments

Comments

@carmenlau
Copy link

We set a complete object to object's relation field, but there is only id leave after saving. Following is the testing code and the output comparison between parse.com and parse-server.

The testing cloud code:

Parse.Cloud.define("testQuery", function(request, response) {
  var objectQuery = new Parse.Query(ObjectClass);
  var Object;

  objectQuery.include('user');
  objectQuery
  .get("_<object_id>_", {useMasterKey: true})
  .then(function(_object) {
    object = _object;
    object.set('user', request.user);
    console.log("1 ======> " + JSON.stringify(object.get("user")));
    console.log("1 ======> " + object.get("user").getUsername());
    return object.save(null, {useMasterKey: true});
  })
  .then(function() {
    console.log("2 ======> " + JSON.stringify(object.get("user")));
    console.log("2 ======> " + object.get("user").getUsername());
    response.success("");
  }, function(error) {
    response.error(error);
  });
});

console log of parse.com:
1 ======> {< full user object >}
1 ======> username
2 ======> {< full user object >}
2 ======> username

console log of parse-server:
1 ======> {< full user object >}
1 ======> username
2 ======> {"objectId":"< user id >"}
2 ======> undefined

@andrewimm
Copy link
Contributor

Which of the two outputs is cloud code, and which is from parse-server? You wrote parse.com twice :)

@andrewimm
Copy link
Contributor

Also, please provide which version of the Parse SDK you are using (console.log(Parse.CoreManager.get('VERSION')))

@carmenlau
Copy link
Author

@andrewimm sorry for confusion! I just updated my comment :P

The first one is parse.com and second one is parse-server

The parse SDK version is js1.8.1

@andrewimm
Copy link
Contributor

Very peculiar. Saving the object shouldn't have side effects on its children. I'll investigate this

@Quaggie
Copy link

Quaggie commented Apr 11, 2016

Parse.Cloud.define("testQuery", function(request, response) {
  var objectQuery = new Parse.Query(ObjectClass);
  var Object; // <-- upperCase `O` and a reserved Javascript constructor

  objectQuery.include('user');
  objectQuery
  .get("_<object_id>_", {useMasterKey: true})
  .then(function(_object) {
    object = _object; // <-- lowerCase `o` and a leaked global since it´s not declared with var
    object.set('user', request.user);
    console.log("1 ======> " + JSON.stringify(object.get("user")));
    console.log("1 ======> " + object.get("user").getUsername());
    return object.save(null, {useMasterKey: true});
  })
  .then(function() {
    console.log("2 ======> " + JSON.stringify(object.get("user")));
    console.log("2 ======> " + object.get("user").getUsername());
    response.success("");
  }, function(error) {
    response.error(error);
  });
});

I'm guessing your parse server configuration isn't injecting globals even though Parse.com probably does. Try to run this code with 'use strict';

@airdrummingfool
Copy link

@carmenlau do you have a beforeSave function defined for the ObjectClass class? And what Parse.com SDK version did you use to run the test cloud code?

@stale
Copy link

stale bot commented Feb 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Feb 6, 2019
@stale stale bot closed this as completed Feb 13, 2019
@dplewis dplewis added resolved and removed stale labels Nov 9, 2020
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

No branches or pull requests

5 participants