Make delicious recipes!

Types of mappings

  1. One-to-one Mapping:
    This is the simplest mapping between two objects.

    For example: every person has a unique finger-print.
    So if person and finger-prints are two separate tables in a database, then it can be said that those two tables have a one-to-one mapping.
    Typically, one-to-one mapping fields are recommended to be put in the same table to avoid costly joins when reading.

  2. One-to-many Mapping:
    Consider an author who has written several books.
    If authors and books are kept in two tables, then there is a one to many mapping from author table to book table.
    Such a relationship is stored using:
    1. A third table storing author-id vs book-id.
    2. Storing a foreign key, such as author-id in book table.

  3. Many-to-one Mapping:
    This is just the inverse of the one-to-many mapping.
    For instance, in the above case, book table has many-to-one mapping with the author table.

  4. Many-to-many Mapping:
    Consider a relationship between a person and the types of car owned by him.
    Clearly, it is a one-to-many relationship because a single person can own different types of cars like sedan, coupe etc.

    But the relationship is one-to-many from car-type table to persons table also because a given car-type can be owned by many individuals.
    Example, sedan can be owned by more than one persons.

    Thus, in such a case, there exists a many-to-many relationship between person and car-type table.

Knowing the type of relationships between table formalizes the relationship and makes it easier to describe.

Like us on Facebook to remain in touch
with the latest in technology and tutorials!

Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Email: (Your email is not shared with anybody)

Facebook comments:

Site Owner: Sachin Goyal