0

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?

1 Answer 1

1

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
   })
})
Sign up to request clarification or add additional context in comments.

2 Comments

But it makes response really heavy, I want few columns from 'Post'. and only 'id' for 'postAuthor', normally it gives all columns from 'user' table as well.
To limit the fields in 'Post', use the Parse.query.select. If you haven't asked for the query to include the user, it wont . i.e, you must NOT have the line 'query.include("postAuthor");'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.