Skip to content

How to query object contain in field type array of pointer? #4659

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
sonysm opened this issue Mar 18, 2018 · 5 comments
Closed

How to query object contain in field type array of pointer? #4659

sonysm opened this issue Mar 18, 2018 · 5 comments

Comments

@sonysm
Copy link

sonysm commented Mar 18, 2018

Hello,

I have one question about query object
Example my data has field "students" type as array pointer of "student" class

students [
{"__type": "pointer", className: "student", "objectId": "123"},
{"__type": "pointer", className: "student", "objectId": "1234"},
]

I want get all field has student object (objectId: 123)

Anyone can help please?
sorry for my poor English

@dplewis
Copy link
Member

dplewis commented Mar 23, 2018

@sonysm Why not use Parse Relations? You can then query for whatever object you want.

Its easier to maintain than an Array of Pointers

@dplewis dplewis closed this as completed Jun 14, 2018
@acinader acinader reopened this Jul 13, 2018
@acinader
Copy link
Contributor

From the JS guide:

"Arrays are ideal when we know that the number of objects involved in our one-to-many relationship are going to be small. Arrays will also provide some productivity benefit via the includeKey parameter."

@sonysm https://docs.parseplatform.org/js/guide/#using-arrays

const needle = {"__type": "pointer", className: "student", "objectId": "123"};
new Parse.Query('XXX').equalTo('student', needle).find();

that should do it.

@Guinto
Copy link

Guinto commented Sep 18, 2018

From the JS guide:

"Arrays are ideal when we know that the number of objects involved in our one-to-many relationship are going to be small. Arrays will also provide some productivity benefit via the includeKey parameter."

@sonysm https://docs.parseplatform.org/js/guide/#using-arrays

const needle = {"__type": "pointer", className: "student", "objectId": "123"};
new Parse.Query('XXX').equalTo('student', needle).find();

that should do it.

Make sure to capitalize Pointer

@kimi21
Copy link

kimi21 commented Oct 20, 2018

instead of hardcoding 123 in objectId, how could we keep it variable, what would be the correct syntax then?

@RaschidJFR
Copy link
Contributor

instead of hardcoding 123 in objectId, how could we keep it variable, what would be the correct syntax then?

I guess this way:

const id = "123";
const needle = {"__type": "pointer", className: "student", "objectId": id};
new Parse.Query('XXX').equalTo('student', needle).find();

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

6 participants