Use an array of pointers to retrieve objects Parse API

427 Views Asked by At

I'm using Parse API with swift. In _User class, I have a column called posts which contains an array of pointers. This is stored by calling

PFUser.currentUser().setObject([PFObject], forKey: "posts")

The pointers in the array are just PFObjects of the posts that the user has uploaded. The posts contain some String values like title and comments, as well as an array of images.

Since PFUser is cached locally, is it possible to retrieve the images by calling

currentUser().objectForKey("posts")

or do I have to make a query call?

I'm currently getting the objectIds from the array of pointers, and calling query.findObjects() with whereKey caintainedIn: [objectId] to retrieve all posts info. But I think if my posts class gets very large, this is very inefficient because every objectId in posts class is being compared to my objectIds.

Is there a way to efficiently retrieve all objects from an array of pointers?

1

There are 1 best solutions below

3
Wain On

As per the comment from @pbush25 a relationship may suit you better.

For a small array of pointers you don't need to do a find request, but for the User class you do need to fetchInBackgroundWithBlock: (just once, before you try to use it) to get the custom columns of data as getting the currentUser() only includes the standard columns of data.