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.
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.
[[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.
Table of Contents
Next Section