简体   繁体   中英

Check if PFObject is in PFRelation

I am building an iOS in Swift using Parse.com as my backend.

I have a table of objects: car, and each car can be owned by multiple users, so I have a Car table with the column owners which is a PRRelation of the _User table.

I am displaying all the cars in a TableView and want to determine (for each object) whether the PFUser.currentUser() is in the Relation of _User objects for each car.

Is there a way of doing this without creating a query which then makes a request to the Parse server? Doing that seems very inefficient to have to check again for each object, and would make a large number of Parse database calls which would make me hit the call limit quite quickly if multiple people are using the app...

So is there a way to simply do something like:

if carObject["owners].contains(PFUser.currentUser()) {

   println("the current user is an owner of this car")

}

Might it be possible to run a query of all cars, and then another query of all the cars with a whereKey restriction on the students column and then comparing queries? How could I compare the queries?

Have you created your car class in your app? You can download all your car objects from parse at once, put them in an [Car] and then you'll have all the relational data as well.

I'm not 100% sure but you may need to use parsequery.includeKey("users") when you query parse so it also includes the parse user. User's being an attribute of Car.

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