Search code examples
javascriptparse-platform

How to write a inner join in parse javascript with Pointer


I have two classes one is _User and another is Vehicle. In _User Class there is a field named "Location"(GeoPoint), and in Vehicle there is a column named "assignTo"(pointer, points to _User Class's ObjectId). Now I want to get fetch User within 10 Km along with his vehicle details.

Note- _User and Vehicle has one to one relationship.And Vehicle's Class column AssignTo (pointer) Points to _User's class ObjectId


Solution

  • Try this one

    //var currentLocation
    var q_u = new Parse.Query(Parse.User);
    q_u.near("Location", currentLocation);
    q_u.withinKilometers(10);
    //inner query is a short cut to get ids, and fetch the next one
    //but the query max limit is 1000, if q_u.count() >1000, it not get all for you
    var query = new Parse.Query("Vehicle");
    query.matchesQuery("assignTo", q_u );
    query.include("assignTo");
    query.find().then(function(vehicles){
        //do what you want
    })