Created
June 25, 2014 04:02
-
-
Save auggernaut/e0cdeb6338d674b76697 to your computer and use it in GitHub Desktop.
nested query to Parse from client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetchCards: () -> | |
# Gets 10 random cards from Card class | |
Choice = Parse.Object.extend 'Choice' | |
Card = Parse.Object.extend 'Card' | |
cardQuery = new Parse.Query Card | |
cardQuery.limit 10 | |
cardQuery.find | |
success: (cards) => | |
choiceQuery = new Parse.Query Choice | |
done = 0 | |
for j in [0..cards.length-1] | |
@_game[cards[j].id] = { question: cards[j].get('question'), choices: null } | |
choiceQuery.equalTo 'cardId', cards[j].id | |
choiceQuery.find | |
success: (choices) => | |
pChoices = [] | |
for i in [0..choices.length-1] | |
pChoices.push { id: choices[i].id, text: choices[i].get('text'), image: choices[i].get('image')} | |
@_game[choices[0].get('cardId')].choices = pChoices | |
if done is cards.length-1 | |
@emit Constants.stores.CHANGE | |
else | |
done++ | |
error: (error) -> | |
console.log "Error fetching choices: " + error.code + " " + error.message | |
error: (error) -> | |
console.log "Error fethcing cards: " + error.code + " " + error.message | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment