Skip to content
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

How to return array of Parse Objects instead of array of pointers in Cloud Code? #67

Closed
d370urn3ur opened this issue Oct 27, 2015 · 6 comments

Comments

@d370urn3ur
Copy link

I perform a query and get an array of parse objects. But when I try to return them using response.success(results), they get converted into just pointers. Here is the log just before I call response.success(results):

[{
      "ans1Goals": 1,
      "ans2Goals": 2,
      "ansSpectators": 21400,
      "createdAt": "2015-10-05T11:00:38.447Z",
      "position": 1,
      "updatedAt": "2015-10-27T10:18:55.294Z",
      "objectId": "39QCu6oTBx"
    }]

and this is what I receive from calling response.success(results):

    [{
      "__type": "Pointer",
      "className": "Answers",
      "objectId": "39QCu6oTBx"
    }]

Why is this happening? On the client side, iOS and Android, we need the parse objects, otherwise with the pointers we will have to make another request to fetch the data. I don't want to return JSON because we have subclassed parse objects in iOS and Android and this should happen automatically, just like when we make queries directly from the clients. Having to parse JSON into ParseObjects defeats the purpose of subclassing in the first place. Thanks for any insight!

@parse-github-bot
Copy link

Thank you for your feedback. We use the issue tracker here to track valid bugs in our SDK. Your question seems to be more about how to use Parse. Could you check out the following resources?

@wangmengyan95
Copy link
Contributor

Hi @d370urn3ur, we do not send the nested ParseObject's full data to cloud code. In order to get the data of the nested ParseObject, you have to do a query or fetch. The result you get from cloud code is pretty similar to the result you get from ParseQuery. We represent nested ParseObject as pointer and you have to fetch or query it in order to use it.

@roddylindsay
Copy link

in the JS SDK 1.5.0 you could call object._toFullJSON(["HACK"]) which would include the complete object and any nested children. Haven't tried it on 1.6.

@d370urn3ur
Copy link
Author

@wangmengyan95 I'm not worried about nested objects now. I want an array of top level parse objects. Let's say I have an object Car like

{
"objectID": "1234",
"color": "red",
}

If I do a query and get all of the Car objects in the database, the results of this query should be an array of Car parse objects. So what you're saying is that if I call response.success(carResults), then I should receive an array of Car Parse Objects at the client. Specifically for iOS a Car subclass of PFObject. But that is not what is being sent by response.success(carResults). Instead of

[ { 
"objectID": "1234"
 "color": "red"
} ]

I get this:

[{
"objectID": "1234",
"className": "Car",
"__type": "Pointer"
}]

So if I want to get the information for this object, I have to call fetch. It's not normal, I am performing one request to get an array of objects and then a request for each object to fetch the rest of the data. request.success() is modifying the carResult and converting the objects into pointers. I don't know if its supposed to work like that or not, it seems like a bug to me. This kind of workflow doesn't make any sense, the goal is to minimize the number of network requests.

@andrewimm
Copy link
Contributor

Which version of the SDK are you using with Cloud Code? There was an issue with this, but it has since been resolved.

@d370urn3ur
Copy link
Author

I was on latest, so theoretically 1.6.7. I manually specified 1.6.7 just in case, and now it is working. I don't know what latest is pointing to but that seems to have been the problem. Thanks you guys for your help!

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