0

So I'm working on a project with javascript and parse.com where each user will be associated with a facility. Each facility has their own number so I have an array with those facility numbers in the user's object. When that user logs in, there will be an array with those facility numbers that I need to make a query with. I looked at the docs and saw a log of querying with arrays but they didn't seem to fit my needs.

I want an array back with each facility object from the facility table. Here's a quick chart of the class structures:

User:[userInfo(username, pass, etc]|[facilities(array)]

Facilities:[facilityName]|[facilityNumber]|[etc]

So the user could be associated with multiple facilities. I need to take the array of facility numbers and get back an array of those facilities. So facilities could be [1,2,11] and it would give back three different facility objects in an array.

I tried this:

function loadFacilities(user) {

    var facilitiesArray = user.get("facilities");

    var query = queryWithClassName("facilities");

    query.equalTo("facilityNumber", facilitiesArray);

    query.find().then(function (results) {

        console.log(results);

    });

}

Knowing I would most likely get a 400 bad request error because facilityNumber is a number, not an array like facilities.

So what's the best way to go at this. I can easily create a query for each entry in the facilities array but that is very inefficient.

1 Answer 1

4

Simply replace your equalTo with containedIn:

query.containedIn("facilityNumber", facilitiesArray);

Documentation here: http://parse.com/docs/js/symbols/Parse.Query.html#containedIn

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.