1

I am querying both the local data store and the server for PFObjects. To try and save mobile data usage and networking usage, the data is first looked up in the local data store and then whatever has not been found is looked up on the server.

The code to figure out which PFObjects have not been found yet is:

let response = objects as! [PFObject]
var responseObjectIds = [String]()
for x in response {
    responseObjectIds.append(x.objectId!)
}
query.whereKey("objectId", notContainedIn: responseObjectIds)

This seems to work fine with normal queries, but breaks down when trying to do the same thing with queries created from Relations.

I think I read somewhere that the whereKey method implementations are slightly different for Relation queries, but I don't think it is very well documented.

Any help improving the code or suggesting new solutions would be greatly appreciated.

Tom Elliott
  • 1,908
  • 1
  • 19
  • 39
Acoop
  • 2,586
  • 2
  • 23
  • 39

1 Answers1

0

The query on a relational column will be expecting a PFObject and not a string/(in this case) an array of strings, I believe.

You will need something like the following:

let relation = PFObject(withoutDataWithClassName: "yourClassName", objectId: response.objectId)
query.whereKey("objectId", notContainedIn: relation)
RJH
  • 358
  • 3
  • 12
  • So how would I modify the last line, `query.whereKey("objectId", notContainedIn: responseObjectIds)` to create this restraint correctly for a `Relation` query? – Acoop Aug 31 '15 at 22:01
  • I understand that it needs an array of PFObjects to check against, but what should I pass in as the key? – Acoop Aug 31 '15 at 23:31
  • please see revision above which may help – RJH Sep 01 '15 at 08:08