Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Simply replace your equalTo with containedIn:

query.containedIn("facilityNumber", facilitiesArray);

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

share|improve this answer
    
Ahhh... I misread that. Thank you! –  evan.stoddard Jun 25 '14 at 23:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.