In the next section, you'll give the application the ability to insert, update, and delete movie roles for the selected movie. This read-write scenario requires a slight modification to the way you access movie role information. To be able to insert new movie roles for a movie, you need a WODisplayGroup for managing MovieRole objects.
Recall that the movieRole variable was created automatically when you bound movies movieRoles to the repetition's list attribute. Since you disconnected the list and item bindings, you don't need the movieRole variable anymore.
WebObjects Builder creates a variable named movieroles in the MovieDetails component. movieroles is a WODisplayGroup that manages MovieRole objects.
- init { [super init]; [movieroles setDataSource:[[movies dataSource] dataSourceQualifiedByKey:@"movieRoles"]]; return self; }
The second line of this method assigns a new data source to the movieroles display group. A data source-an instance of an EODataSource subclass-is an object that defines a basic interface for providing enterprise objects. It exists primarily as a simple means for a WODisplayGroup or other higher-level class to access a store of objects. For example, when you tell a display group to fetch, it does so by telling its data source to fetch.
To restrict the objects that movieroles displays, you need to replace movieroles' data source with a detail data source. A detail data source is a data source that qualifies (restricts) its set of enterprise objects to an object that's selected in a master data source. A detail data source is set up to provide objects for the destination entity of a particular relationship.
The following expression:
[[movies dataSource] dataSourceQualifiedByKey:@"movieRoles"]gets the data source from the movies display group and asks it to provide a detail data source. The data source returned by dataSourceQualifiedByKey: is set up to provide MovieRole objects that are related to one of movies' enterprise objects through the movieRoles relationship.
- setMovie:aMovie { if (aMovie) [movies setObjectArray:[NSArray
arrayWithObject:aMovie]]; else [movies setObjectArray:nil]; [movies selectObject:aMovie]; // Add the following lines. [[movieroles dataSource] qualifyWithRelationshipKey:@"movieRoles" ofObject:aMovie]; [movieroles fetch]; }
WebObjects Builder adds the movieRole variable back and automatically binds it to the repetition's item attribute.
movieRole's displayedObjects method returns an array of roles in the selected movie. In general, WODisplayGroup's displayedObjects method returns the list of objects that you want to display.
Typically, a display group's object array contains more objects than the display group makes available for display. Most display groups fetch all of the objects in the database, and you usually do not want to display all of the objects in the database. To display fewer objects, you associate a qualifier with the display group. After the display group has performed the fetch, it applies the qualifier to the fetched objects. displayedObjects returns an array that either contains the entire array of objects after the qualifier has been applied, or if the batch size is greater than 0, it returns the objects in the current batch.
For example, suppose there are one thousand records in the database. A typical display group would fetch all one thousand records. Then suppose the display group had a qualifier that narrows the list down to one hundred objects that should eventually be displayed. If the batch size is 0 (indicating that the display is not being batched), displayedObjects returns all one hundred objects that should be displayed. If the batch size is ten, displayedObjects returns the ten objects out of those one hundred that currently should be displayed. When the page is loaded, displayedObjects returns the first ten objects. When the Next Page button is clicked, displayedObjects returns the next ten objects, and so on.
Table of Contents Next Section