Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

How to perform relational queries with Pointers? #51

Closed
cetorres opened this issue Jan 21, 2019 · 17 comments
Closed

How to perform relational queries with Pointers? #51

cetorres opened this issue Jan 21, 2019 · 17 comments

Comments

@cetorres
Copy link

I have a class Customer that has a property user. That's a Pointer to User. How can I perform a query that does this where?

where={"user":{"__type":"Pointer","className":"_User","objectId":"8TOXdXf3tz"}}

@phillwiggins
Copy link
Member

phillwiggins commented Jan 21, 2019 via email

@cetorres
Copy link
Author

Can you give an example, please?

@phillwiggins
Copy link
Member

phillwiggins commented Jan 21, 2019 via email

@cetorres
Copy link
Author

I saw that one: .includeObject(['Day']). But that just includes the Pointer data into the main query. But doesn't filter by the objectId, which is what I want.
There query is like, give me the customers from this user.

With this request I can achieve the query:

https://YOUR.PARSE-SERVER.HERE/parse/classes/Customer?where={"user":{"__type":"Pointer","className":"_User","objectId":"8TOXdXf3tz"}}

But how to do it with the QueryBuilder? Now I can only do with custom query from the ParseObject.

@phillwiggins
Copy link
Member

phillwiggins commented Jan 21, 2019 via email

@cetorres
Copy link
Author

cetorres commented Jan 21, 2019

No. It would be using whereEqualTo('user', user). Sending the user as a ParseUser doesn't work. I believe because Parse stores this user on Customer class as a Pointer to User. So it's a Pointer object. So the solution would be perform a subquery, as the REST API suggests, do a inQuery:

&where={"user":{"$inQuery":{"where":{"objectId":"${user.get('objectId')}"},"className":"_User"}}}

But I don't see any method to do find an object as a result of a query. On the regular Parse SDK for iOS and Android we can find it.

@phillwiggins
Copy link
Member

phillwiggins commented Jan 21, 2019 via email

@cetorres
Copy link
Author

https://docs.parseplatform.org/rest/guide/#relational-queries

@phillwiggins
Copy link
Member

phillwiggins commented Jan 21, 2019 via email

@cetorres
Copy link
Author

Ah ok, good to know. Thank you.

@RodrigoSMarques
Copy link
Contributor

@cetorres
It's working. You can test with last release.

      var queryBuilder = QueryBuilder<ParseObject>(ParseObject('Product'))
        ..whereEqualTo("owner", user.toPointer());

@RodrigoSMarques
Copy link
Contributor

@phillwiggins
this issue can be closed.

Resolved in the last release.

@cetorres
Copy link
Author

Thank you, guys!

@RodrigoSMarques
Copy link
Contributor

@cetorres
you are Brazilian?

@cetorres
Copy link
Author

Yes, @RodrigoSMarques. You too?

@RodrigoSMarques
Copy link
Contributor

Me too. I live in Vitória - ES.

Nice. I speak. I know a few Brazilians who use Parse.

@RodrigoSMarques
Copy link
Contributor

@phillwiggins
Close this issue to keep open only what is in trouble.
Resolved in previous releases. It is inactive because it has not received any new comments.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants