Note that there are some explanatory texts on larger screens.

plurals
  1. POParse.com -- Add on values from a second class/object
    primarykey
    data
    text
    <p>So I'm using Parse.com and their AnyPic app as a starting point. It's an Instagram clone. However, unlike Instagram, the comments for pictures aren't included on home page. You have to tap the picture and it brings up a DetailsVC with the commments. This is the first thing I'm trying to change.</p> <p>I'm new to Parse (and backends in general) and am having trouble trying to modify the query to return the comments. If you've used AnyPic, you know that the comments aren't saved in the <code>Photo</code> class but in a separate <code>Activity</code> class:</p> <p><img src="https://i.stack.imgur.com/1yqYV.png" alt="enter image description here"></p> <p><code>Activity.type</code> would equal <code>comment</code> and <code>Activity.content</code> would be the comment text.</p> <hr> <p>SO, the VCs in AnyPic subclass Parse's <code>PFQueryTableViewController</code>, overriding the <code>queryForTable</code> method to fetch data. Here's the <code>queryForTable</code> for their AccountVC, which returns ONLY the photos:</p> <pre><code>- (PFQuery *)queryForTable { if (!self.user) { PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; [query setLimit:0]; return query; } PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; query.cachePolicy = kPFCachePolicyNetworkOnly; if (self.objects.count == 0) { query.cachePolicy = kPFCachePolicyCacheThenNetwork; } [query whereKey:kPAPPhotoUserKey equalTo:self.user]; [query orderByDescending:@"createdAt"]; [query includeKey:kPAPPhotoUserKey]; return query; } </code></pre> <p>And the <code>queryForTable</code> for the DetailsVC, which will return comments for the photo object passed to it in <code>self.photo</code>:</p> <pre><code>- (PFQuery *)queryForTable { PFQuery *query = [PFQuery queryWithClassName:self.parseClassName]; [query whereKey:kPAPActivityPhotoKey equalTo:self.photo]; [query includeKey:kPAPActivityFromUserKey]; [query whereKey:kPAPActivityTypeKey equalTo:kPAPActivityTypeComment]; [query orderByAscending:@"createdAt"]; [query setCachePolicy:kPFCachePolicyNetworkOnly]; // If no objects are loaded in memory, we look to the cache first to fill the table // and then subsequently do a query against the network. // // If there is no network connection, we will hit the cache first. if (self.objects.count == 0 || ![[UIApplication sharedApplication].delegate performSelector:@selector(isParseReachable)]) { [query setCachePolicy:kPFCachePolicyCacheThenNetwork]; } return query; } </code></pre> <hr> <p>I just can't wrap my head around how to combine the two queries into one and have it return photo objects with comment values attached.</p> <p>I've thought to just run a separate query for the comments in <code>tableView:numberOfRowsInSection:</code> once <code>queryForTable</code> returns a set of photos, but I'm thinking it's better if I let Parse's <code>queryForTable</code> handle it in case there's some caching going on that might be useful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload