Object Relational Mapping

How we get stuff in and out of databases

go back! retreat!

What is object relational mapping?

Object relational mapping, also known as ORM, is how we as programmers manage and interact with the data we're using to create a website or a piece of software.

How do you use it?

We used this concept in our final project, Black Thursday, wherein we created a database from scratch and used our structure to run analytics on business e-commerce data.

What does it look like?

The Black Thursday object relational map looks like this:

A visual representation of an object relational map

But what does it mean?

Each of the sticky note lists in the image above correspond to "repositories" containing a huge list of each type of item. Each of the items in a repository has the attributes listed within the sticky note.

You may notice, however, that not every item "knows about" every other item. For example, an invoice knows which customer and which merchant it belongs to, but not about its own invoice items.

In this project, we had to create complex data relationships so that one could, for example, find the revenue for a single merchant.

To do this, we had to:

  1. Select an individual merchant using their id.
  2. Collect all the invoices belonging to that merchant.
  3. Collect all the invoice items for each of those invoices.
  4. Calculate the total revenue for each invoice item (unit_price * quantity).
  5. Sum all of those revenues.

To accomplish each step, we had to create relationships between the items and repositories so that each item in the hierarchy "knew" about the repository above it, and could traverse the structure while also holding the relevant identifying data for the items sought.

Is it hard?

In a perfect world, an ORM would not be hard to use, and would help immensely in visualizing your data structure.

But in the real world, databases are often set up incorrectly or by non-technical users, and so there are errors in the structure that can make your task harder, regardless of how the ORM says your database is supposed to work.

This was the case with our project. For many of the requirements, one could in theory traverse the structure in several ways to get to the same result, but in practice, there was only one way, and that way could only be found through trial and error.

But why?

¯\_(ツ)_/¯

Really, though, it was meant to help us get used to complex business requirements and navigating mission-critical structures, which will always have imperfections and quirks of their own.

Will I be okay?

You'll be fine. Mod 1 is really fun and cool, and will truly help you find out if you like projammin', which I definitely do.

Thanks to Mike, Sal, and Ali for being great instructors and making sure none of us went (too) crazy.

This is the internet. Where are the cat gifs?