beautypg.com

Setting up a master-detail configuration, Setting up a master-detail configuration 104 – Apple WebObjects 3.5 User Manual

Page 104

background image

Chapter 3

Creating a WebObjects Database Application

104

Enterprise Objects Framework provides several mechanisms for generating and
assigning unique values to primary key attributes. By default, Enterprise
Objects Framework uses a native database mechanism to assign primary key
values. See the chapter “Answers to Common Design Questions” in the
Enterprise Objects Framework Developer’s Guide for more information.

The Movies application generates primary key values for Movie and Talent
objects using the default mechanism, but MovieRole is a special case because:

MovieRole’s primary key is compound. The default behavior of generating
a primary key value using a native database mechanism works only on
simple (not compound) primary keys.

A MovieRole’s primary key attributes,

movieId

and

talentId

, must match the

corresponding attributes in the MovieRole’s Movie and Talent objects. The
default mechanism generates new, unique values.

Instead of the default mechanism, Enterprise Objects Framework uses primary
key propagation to assign primary keys to MovieRole objects. By configuring
the Movie’s

movieRoles

relationship to propagate primary key, the Framework

knows to assign a new MovieRole’s

movieId

to the same value as the

movieId

of the

MovieRole’s Movie. Similarly, a new MovieRole’s

talentId

is set to the same value

as the

talentId

of the MovieRole’s Talent.

Setting Up a Master-Detail Configuration

So far your Movies application fetches, inserts, updates, and deletes only Movie
objects. Considered alone, a Movie object isn’t as interesting as it is when it’s
related to actors and roles. In this section, you’ll add MovieRole and Talent
objects to the Movies application.

The relationships defined in your model now come into play. Using Movie’s

movieRoles

relationship, you can display the MovieRoles for the selected Movie.

In this type of configuration, called master-detail, a master display group holds
enterprise objects for the source of a relationship, while a detail display group
holds records for the destination. As individual records are selected in the master
display group, the detail display group gets a new set of enterprise objects to
correspond to the selection in the master.