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.
-
Form a to-many relationship to the Movie (destination) entity.
-
The source attribute is studioID. The destination attribute is studioID.
-
Name the relationship movies.
-
Form a to-one relationship to the Studio (destination) entity.
-
The source attribute is studioID. The destination attribute is studioID.
- Name the relationship studio.
-
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 attribute.
Adding Movies to the Application
Creating a Master-Detail Interface
© 1999 Apple Computer, Inc. (Last Updated 13 Sep 99)