简体   繁体   中英

How to get query.whereKey(key, containedIn: [Array]) to work with relation.query

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 PFObject s 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM