Documentation Archive Developer
Search
PATH  Documentation > WebObjects 4.5 > Creating a Java Client Application: A Tutorial

   

Adding Relationships

Creating an application that adds and modifies studios is just the first stage of the StudioManager application. Now you can enhance the application to display all of the movies owned by a selected studio.

The Studio, Movie, and Talent entities are not especially interesting when considered separately. Their real significance only becomes apparent in their relationships to each other. Every Movie has one corresponding Studio. One Studio can have many Movies. A particular actor (Talent) can star in several movies.

Relational databases model not just individual entities, but entities' relationships to one another. For example, a Movie entity has a corresponding Studio entity. This is modeled in the database by both the Movie entity and the Studio entity having a studioID attribute. In Movie, studioID is a foreign key, while in Studio it's a primary key. A foreign key correlates with the primary key of another table in order to model a relationship a source table (Movie) has to a destination table (Studio). In the following diagram, notice that the value in the STUDIO_ID column for both movies is "501". This matches the value in the STUDIO_ID column of the Columbia Pictures movie studio. In other words, the movies "Tootsie" and "Taxi Driver" both belong to Columbia Pictures.

This plays out in your running application as follows: Suppose you fetch a Movie object. Enterprise Objects Framework takes the value for the movie's studioID attribute and looks up the studio with the corresponding primary key.

For your application to take advantage of such database-defined relationships, your model must specify the corresponding relationships. When you created the model using the wizard, EOModeler created relationships between your selection of entities based on matching primary and foreign keys; it assigned relationship names of the form "toDestinationEntity". You might have reason now to examine these relationships, add new ones, delete generated ones, or modify things such as whether a relationship is to-one or a to-many.

Note:   Your model may already have some relationships in it, based on information EOModeler read from the database. For the purposes of this tutorial, you can just ignore these relationships.

You need to ensure that the following relationships are specified:

From the Studio (source) entity:

From the Movie (source) entity:



  1. Create a relationship.

    Display the attributes view for the entity you want to use as the source of the relationship.

    Choose Property Add Relationship.

    In the Relationship Inspector, enter the name of the relationship.

    Select whether the relationship is to-one or to-many.

    Select a destination entity.

    Select a source attribute.

    Select a destination attribute.

    Connect them.

Adding Movies to the Application

Creating a Master-Detail Interface


© 1999 Apple Computer, Inc. – (Last Updated 13 Sep 99)