Multilevel query to a pointer property.

22 views
Skip to first unread message

Yesid Lazaro

unread,
Jul 12, 2019, 4:39:53 PM7/12/19
to Back4App
Hi, i want to know how to query in a class that has a property (Pointer) pointing to another class, for example

Class : Store [id, name, address,status]
Class : Product [id, name, store(Pointer)]

so, i want to get the only the products where the store.status is equals to "x", 
i doing it in a cloud code function in js and the query es something like that but is returning zero elements . 
var query = new Parse.Query(ProductClass);
query.descending("views");
query.include("store");
query.equalTo("store.status", "active");
let hotPromos = await query.find({ useMasterKey: true });
thanks in advance. 

Davi Macêdo

unread,
Jul 12, 2019, 5:09:29 PM7/12/19
to Back4App
You will have to use "matchesQuery" operator (https://docs.parseplatform.org/js/guide/#relational-queries). It would be something like this:

var innerQuery = new Parse.Query(StoreClass);
innerQuery.equalTo("status", "active");

var query = new Parse.Query(ProductClass);
query.descending("views");
query.include("store");
query.matchesQuery("store", innerQuery);
Reply all
Reply to author
Forward
0 new messages