Part 1 : Table relations :
Entity Mappings are nothing but Implementation of relation between two Entity Objects. In order to do that, first lets understand the relation between physical tables or Database tables.
One table may relate with another table in many ways.
These are the relations :
1.One to one
2.One to Many / Many to One
3.Many to Many
One to One :
One entry/ row /id in a table , is related exactly with another entry/row/id in another table.
Consider a scenario where each User has only one Account.
We can also say this as “One and Only” relation. When we say so, cardinality symbol changes to double line like this
Consider this case. A User has only one entry in Access table. But it is optional for the user to have access or not to have. We represent optional behavior ( Zero record) with open circle near the table where the optionality exists.
One to Many / Many to One :
One entry in one table can have many entries in another table.
Many entries in one table may relate to one single entry in another table.
In the above tables relation, for one entry in program table there could be zero or many entries in Batch table; Similarly zero or many batches can point to one single entry in program table.
program_id in program table is foreign key to batch table with column name batch_program_id.
Please note these symbols :
Many To Many : One row in a table is related to more than one record in another table and vice versa.
We can't implement this relation, just with 2 tables. We need a Joining table/Junction table also.
Consider this scenario of List of Apps used by a List of Users.
One Application is used by many Users.
And one User can use many applications as well. So both tables are in Many To Many relation.
ninja_app_user is the joining table here.
Please note the many symbol on both sides of the joining table.
Part 2 is discussed here.