Skip to content

How to query object contained in the field type array of pointer? #5136

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
kimi21 opened this issue Oct 23, 2018 · 1 comment
Closed

How to query object contained in the field type array of pointer? #5136

kimi21 opened this issue Oct 23, 2018 · 1 comment

Comments

@kimi21
Copy link

kimi21 commented Oct 23, 2018

Issue Description

I have one question about querying objects

Example : I have a products class which has a pointer to Events class through the "event" field. I want to extract all the matched items from Products that belongs to the same Event.

Products class :
"results": [
{
"objectId": "LozokqgJQz",
"price": 9,
"name": "Entree + Conso",
"event": {
"__type": "Pointer",
"className": "Event",
"objectId": "QHIXTBECcv"
}
},
{
"objectId": "CDzofqgJQz",
"price": 10,
"name": "Entree + Conso",
"event": {
"__type": "Pointer",
"className": "Event",
"objectId": "FHIXTZZCcv"
}
},
{
"objectId": "DXzosqgJQz",
"price": 10,
"name": "Entree + Conso",
"event": {
"__type": "Pointer",
"className": "Event",
"objectId": "FHIXTZZCcv"
}
}
]

For example, for an event of objectId "QHIXTBECcv" the following item from Products class should be returned :
{
"objectId": "LozokqgJQz",
"price": 9,
"name": "Entree + Conso",
"event": {
"__type": "Pointer",
"className": "Event",
"objectId": "QHIXTBECcv"
}

Steps to reproduce

What I have done already :

const Product = Parse.Object.extend("Product");
const needle = {"__type": "Pointer", "className": "Event", "objectId": "QHIXTBECcv"};
const query = new Parse.Query(Product).equalTo('event', needle);
const results = await query.find();

//For showing the matched products
for (let i = 0; i < results.length; i++) {
var object = results[i];
alert(object.get('event') + ' - ' + ' Price ' + object.get('price'));
}

Expected Results

I want to be able to supply whatever event objectId to
const needle = {"__type": "Pointer", "className": "Event", "objectId": "QHIXTBECcv"};
instead of hardcoding it to "QHIXTBECcv"
I want some means of specifying a variable name.
something like :
const needle = {"__type": "Pointer", "className": "Event", "objectId": varobjectId};
but it's not working!
What is the correct syntax for doing that? or is there some other way of doing this whole thing?

@georgesjamous
Copy link
Contributor

georgesjamous commented Oct 23, 2018

Quoting from the docs
"https://docs.parseplatform.org/js/guide/#one-to-many"
and here
"https://docs.parseplatform.org/js/guide/#relational-queries"

// Suppose in this game app, we want to make sure that every Game object is associated with a Parse User. We can implement this like so:
var game = new Parse.Object("Game");
game.set("createdBy", Parse.User.current());
// We can obtain all of the Game objects created by a Parse User with a query:
var query = new Parse.Query("Game");
query.equalTo("createdBy", Parse.User.current());
// You can also do relational queries by objectId:
var post = new Post();
post.id = "1zEcyElZ80";
query.equalTo("post", post);

Clearly, you haven't read the docs. 😕

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

3 participants