PFQueryTableViewController using objects in PFObject array

Sorry if this is a very simple and dumb question. I am still new to Parse.

Suppose I have a Schedule object and a Schedule object can have multiple ScheduleItem objects (not many). I decided to model this using arrays for relationships such as:

PFObject *first = ...
PFObject *second = ...
PFObject *third = ...

PFObject *schedule = [PFObject objectWithClassName:@Schedule"];
schedule[@"scheduleItems"] = @[first, second, third];

      

Suppose I want to later query these ScheduleItems that belong to this schedule and use it in the PFQueryTableViewController. I can't just query this schedule and access its elements through an array because PFQueryTableViewController uses the PFQuery results as a data source for the table view. And I'm not sure how to query "the ScheduleItems that live in the 'scheduleItems' array for a specific Schedule object". I can see the request method whereKey:containedIn:

, but it doesn't look exactly like it because I don't have a reference to this array before I make the request. I seem to need to make some kind of nested / compound query, because for part of that query, I need to query the Schedule object, but I don't know exactly how that works.

EDIT . To clarify this issue. Let's assume the Schedule object is named "Today". I know I can build a query for this Schedule object and tell it to include the "scheduleItems" field:

PFQuery *query = [PFQuery queryWithClassName:@"Schedule"];
[query whereKey:@"name" equalTo:@"Today"];    // or query by its objectId
[query includeKey:@"scheduleItems"];

      

I know that if I execute this query with something like findObjectsInBackgroundWithBlock:

, the result of the direct query is an array of one object - the Schedule object, with all available in ScheduleItems via the scheduleItems field.

My problem: I don't want to execute this query myself - I want to use these ScheduleItems as cells in a PFQueryTableViewController, which assumes a one-to-one mapping between cells and direct query result objects. If I use the above query with PFQueryTableViewController, the result of the direct query is an array of one object, meaning the table has only one object. Long story short, I don't know how to tell PFQueryTableViewController to make a request, but then use a linked array of objects to populate the table.

+3


source to share


1 answer


Your choice of using an array over a relationship is perfect for your use case. Because of this, you can specify

[query includeKey:@"scheduleItems"];

      



after the request is created to specify that it should include, inline, and not ask for a second network request, details for objects in the array.

Remember that you must keep the number of objects in the array small to avoid performance and potentially large size issues.

0


source







All Articles