priyanka B
priyanka B

Reputation: 1

Parse client javascript: Query to select only objectId from pointer

If I have structure like below:

_User Structure:

objectId
username
password
name - string

Posts Structure:

objectId
postName - string
postMsg - string
postAuthor - Pointer< _User > (Pointer to the User Class)

I want to query post, and want to include postAuthor's objectId only. Currently I am using something like following:

var Posts = Parse.Object.extend("Posts");
var query = new Parse.Query(Posts);
query.include("postAuthor");

But this query includes author's details in each post, which is duplicate also making response heavy.

Is there is any way to include only postAuther's objectId?

Upvotes: 0

Views: 931

Answers (1)

simonberry
simonberry

Reputation: 930

you dont have to use 'query.include`

the postAuthor field will be a pointer, which includes the id (objectId) :

var Posts = Parse.Object.extend("Posts");
var query = new Parse.Query(Posts);
// filter as required
query.find().then (function (posts) {
   posts.forEach(function (post) {
      console.log('Authors objectId is ' + post.get('postAuthor').id
   })
})

Upvotes: 1

Related Questions