How to use relations between a Parse subclass and an User - Swift

271 views Asked by At

I am building a Quiz App and I have a class named "Questions" in Parse. When my user answers a question, I wanted that question to be removed from the questions that he needs to answer. I then wanted to add a subclass named "QuestionAnswered", a boolean that would return true for questions that the user had already answered. The problem is that this boolean should be unique to each user. How can I implement this in Parse and in swift?

Thank you.

1

There are 1 answers

1
rickerbh On BEST ANSWER

One way you could do it is have a relation to User on Questions called answeredBy, and just add a user to that relation when they answer a question

var relation = question.relationForKey("answeredBy")
relation.addObject(aUser)
question.saveInBackground()

Then, to query questions that haven't been answered by the user just add a questionQuery.whereKey("answeredBy", notEqualTo:aUser) constraint to your question query.

I'm not sure how this will scale though, so YMMV. You might want to do some testing on this if you're expecting decent traffic.