Documentation Archive Developer
Search
Table of Contents Previous Section

Add more entities to the detail page

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.

Before you can use MovieRole and Talent objects in your application, you first need to go back to EOModeler and add relationships to the model's entities.

Relational databases model not just individual entities, but entities' relationships to one another. For example, a movie has zero, one, or more roles. This is modeled in the database by both the MOVIE table and MOVIE_ROLE table having a MOVIE_ID column. In the MOVIE_ROLE table, MOVIE_ID is a foreign key, while in MOVIE it's a primary key. A foreign key correlates with the primary key of another table to model a relationship a source table (MOVIE) has to a destination table (MOVIE_ROLE). In the following diagram, notice that the value in the MOVIE_ID column for both MOVIE_ROLE rows is 501. This matches the value in the MOVIE_ID column of the "Alien" MOVIE row. In other words, "Ripley" and "Ash" are both roles in the movie "Alien."

Suppose you fetch a Movie object. Enterprise Objects Framework takes the value for the movie's MOVIE_ID attribute and looks up movie roles with the corresponding MOVIE_ID foreign key. The framework then assembles an object graph that connects the Movie object with its MovieRoles. As shown below, a Movie object has an array of its MovieRoles, and the MovieRoles each have a Movie.

After you add relationships to your model, you can access MovieRole and Talent objects through the Movie objects fetched by the movies display group. Using WebObjects Builder, you'll bind attributes of MovieRole and Talent objects to elements in the Movie Details page.

Add relationships to your model

The Movies application uses two pairs of inverse relationships. The first pair defines the relationship between the Movie and MovieRole entities, while the second pair defines the relationship between the MovieRole and Talent entities. An Enterprise Objects Framework relationship is directed; that is, a relationship has a source and a destination. Generally you'll define a relationship for each direction.

  1. In EOModeler, double-click the open entity icon for the Movie entity.

  2. Choose Property Add Relationship.

    A new relationship named "Relationship" is added in the table view at the bottom of the model file window.

  3. Choose Tools Inspector.

    The Relationship Inspector opens.

  4. Select the To Many option.

  5. Select MoveRole as the destination entity.

  6. Select movieId in the Source Attributes list.

  7. Select movieId in the Destination Attributes list.

  8. Click Connect.

    EOModeler automatically renames the relationship based on the name of the destination entity. For example, after connecting a to-many relationship from Movie to MovieRole, EOModeler names the relationship "movieRoles." To-one relationships are named with the singular form of the destination entity's name. For example, EOModeler names the inverse to-one relationship (from MovieRole to Movie) "movie."

  9. Repeat the steps above to create the following relationships:

    A to-one relationship in the MovieRole entity where:

    A to-one relationship in the MovieRole entity where:

    A to-many relationship in the Talent entity where:

Save the model file

  1. Choose Model Save.

    A Consistency Check panel runs alerting you that several of the model's entities don't have primary keys.

  2. Click OK to save your model anyway.

    You'll add primary key values in the next step.

Assign primary key attributes

The Database Wizard assigned a primary key attribute to the Movie entity when it created the model. You need to assign primary keys to the rest of the entities using EOModeler.

The Movies application only uses the Movie, MovieRole, and Talent entities, but you should assign primary keys to all the entities in case you extend the application later.

  1. Click the model icon in the icon path to display the model's entities.

  2. Select the Director entity icon.

  3. Open the inspector.

  4. Click in the primary key column next to the movieId and talentId attributes to make them primary keys.

  5. Repeat the steps above to specify the following primary keys for the remaining entities:

    Note that some of the entities have compound primary keys; that is, a primary key that is composed of more than one attribute.

    Now when you save, EOModeler should not display the Consistency Check panel.

Add interface elements for the new information

Now you'll extend the user interface of the MovieDetails component to display the actors in the selected movie. Because different movies have different numbers of roles, you need the dynamism of a repetition element.

  1. In the MovieDetails component window, add the bolded text Starring: beneath the Revenue line.

  2. Place the cursor below the Starring label.

  3. Drag a repetition element into the component window from the Abstract Elements palette.

  4. Delete the "Repetition" text inside the element and the carriage return before it.

  5. Add three string elements inside the repetition.

    The strings should all be on the same line, so don't type carriage returns between them.

  6. Type the word "as" between the last two string elements.

Create bindings

  1. Select the first field of the repetition element.

  2. Navigate to movies movieRoles in the object browser.

  3. Double-click movieRoles.

    Remember that a Movie object has a movieRoles instance variable that's an array of MovieRole objects. The steps above bind the movieRoles array of the selected Movie object to the repetition's list attribute. WebObjects Builder automatically adds a new variable to the MovieDetails component named movieRole and binds it to the repetition's item attribute.

    The movieRole variable, a MovieRole object, has an instance variable-talent-that's a Talent object. (The talent instance variable is the result of the to-one relationship from the MovieRole entity to the Talent entity.) Through the movieRole instance variable, you can access the name of the actor playing a particular role.

  4. Select the first string element in the repetition.

  5. Navigate to movieRole talent firstName in the object browser.

  6. Double-click firstName.

  7. Similarly, bind movieRole talent lastName to the second string element.

  8. Bind movieRole roleName to the last string element.

Save and run your application

A WebObjects application only reads its model file once-when it loads the corresponding WODisplayGroup. As a result, you'll need to restart your the Movies application so it can see the relationships you added.

You may need the assistance of your system administrator to end the running Movies process, but generally you use the Windows NT Task Manager to end processes.

  1. Right-click on the toolbar.

  2. Choose Task Manager.

    The Task Manager window opens.

  3. Select the WODefaultApp process that corresponds to your Movies application.

  4. Click End Process.

    For Unix Users Only: On Unix systems you can use the kill command to end the WODefaultApp process.

Table of Contents Next Section