Gustaf Gunér
Gustaf Gunér

Reputation: 2267

Parse iOS Swift object key inside whereKey

Is it possible to run a whereKeyon a PFQuery with object keys within? Let's say I want to fetch all users with a current score higher than their previous? Something like this:

query.whereKey("score", greaterThan: ?previous?)

In this example, what should I enter instead of ?previous?? Of course I could fetch all users and then make comparisons but that will be slow with many users.

Thanks

Upvotes: 0

Views: 119

Answers (1)

Marius Waldal
Marius Waldal

Reputation: 9952

No, a Parse query can only compare a key against a provided object.

I would suggest making a beforeSave() cloud code event that compares the new score with the previous upon saving and then sets another column (i.e. newHighscore) to 1.

You can then query for all users with newHighscore equalTo 1. Next time you save the user score, if it's not higher than the previous score, you set newHighscore to 0.

Upvotes: 1

Related Questions