0
votes

I'm creating a voting system for records I have stored in CloudKit. Each record is stored with a sum of votes. I want each user to only be able to vote on each record once.

Is there a way to query all records of a given type that have not been modified by a given user?

If this isn't possible any clever suggestions for this problem?

I want to avoid storing id's of records on the user record as that would have poor scaling as the user voting activity and total of records goes up.

1

1 Answers

0
votes

One option would be to store an array of CKReferences as a property of each record, with the CKReferences pointing to users. You could then query with a predicate something like "user IN votingUserReferences". Not sure how that would scale though.

Another option, probably better, is to have a Vote record type, that has a reference to the user, and a reference to the record. If you construct the record id for these Vote records as a concatenation of the user id and the record id, you should be able to very quickly fetch the vote for a given user and record.

The other advantage of setting the record id for Vote that way is that should you try to create a new Vote when the user has already voted on that record, you will get an error, because a record id has to be unique.