Main Menu
Lecture 1
Lecture 2
Lecture 3
Lecture 4
Lecture 6
Lecture 7
 

 

 

Join Tables and compound primary keys

For a many-to-many relationship the data base requires an extra table

Table does not correspond to any class in the application

By flattening relationships in EOM you can ensure each class contains an array

Above Join Table is unusual

no single column in table is sufficient to uniquely identify the row

becausee a given project could appear in the table multiple times (also employee)

Both columns together do uniquely define a row - thus table has a compound primary key

Also, the columns that make up the primary key are foreign keys, which refer to the primary keys of the two entities the table is joining together

EOF does not attempt to generate primary keys for join tables - it simply uses the foreign key values

When not to flatten a relationship

When the join table contains columns other than foreign keys refering to the primary keys of the joined entities, then the table has data of its own in addition to the relationship information

To access this data you have to create a class for the join table