Two types of relationship exists between data models
- Parent - child
- Reference look-up
Let's understand these relationships
by analysing the relationships between the entities in the example application. But first, let's list the relationships, which we had identified in the data modeling section, between the various entities in the example application.
- A product must belong to a category. The product may be available in one or more colours; each colour may be available in one or more sizes.
- A customer can have multiple addresses. A customer can place an order for a product that is available.
||Which of these are "Parent-Child" relationships?
- Customer --> Customer Address; Product Details --> Product Colour; Product Colour --> Product Size; Customer Orders --> Product Orders
the data modeling process, when we normalized the data, we split the
product data into product details, product colour and product size.
Similarly, customer data was split into customer details and customer
address; customer orders was split into orders (summary details) and
product orders (line item details).
Customer address has no significance without customer details i.e. address is of no use if we don't know whose address it is. Similarly, product colour and product size have no significance if a product does not exist; product orders cannot exist without a customer order. This type of a relationship is called as parent-child.
||Which of these are "Reference look-up" relationships?
- Customer --> Customer Order; Product Details --> Category; Product Orders --> Product Details
We know that only an valid (existing) customer can place a customer order. Reference look-up relationship helps to provide the necessary reference list for searching/validating if the customer is valid; similarly for validating category in product details and product details in customer product orders.
You will learn to establish relationships by implementing the above relationships between the data models in our example application.