Object Relational Mapping

by ,

Guest Blog Post from Ben Dotte, Lead Software Developer


Buried in the guts of Collective we utilize a technology called an object relational mapping tool, or ORM. Ominous as it may sound, this technology solves a big problem in the software development world in a big way, and helps us to create database-driven software much more easily and efficiently than we could without it.


At the heart of this problem is the disconnect between object-oriented software development, and relational database systems. Without going too far into the gory details about how classes and inheritance hierarchies work, I’ll try to explain how this works with a simple example. Let’s say you’re creating a system for a grocery store that stores information about different kinds of fruit. A logical way to represent that data might look like this:



This means you have Apples, which are Fruit, and Bananas, which are also Fruit. This is called an inheritance hierarchy, and this type of structure is commonly used to represent data in object-oriented programming systems. That’s great for your application, but how do you then store these apples and bananas into a database? Database tables have only tables and rows of data in those tables. There is no notion of a hierarchy of objects.


This is where object relational mapping comes to the rescue! Object relational mapping allows us to represent hierarchical data like this in a relational database. We send hierarchical data to the ORM system to persist it to the database, and when we request that data back from the database, it comes back to us in the form of this hierarchical representation.


You might be wondering, how does the ORM system do this? There are a variety of techniques, one of which is to add a discriminator column to the database table. This is a column that tells us what type of object a row in the database represents. So for this example we might have a Fruit table with some rows like this:



The type column is the discriminator, and it instructs the ORM system what kind of object to return to us from the database.


This isn’t the only function ORM provides for Collective, but it is one of the primary motivations for using such a system. Working in tandem with the many other frameworks we employ, it is possible to create web-based, database-driven software effectively and efficiently to the benefit of our internal staff and clients alike.

comments powered by Disqus

The Widen Blog

Where marketing and creative teams find actionable advice, practical resources, and success stories to flourish in a world connected by content.

Like what you're reading?

We can send you our best articles.

Justifying DAM Guide

justifying-digital-asset-management

Read this guide to learn how to calculate and justify the value of DAM to your organization

Get the free guide

 

Creative Harmony Guide

The Content Wrangler's Guide to Creative Harmony

Read this guide to help you elevate your brand with better file organization, sharing, and analytics in order to keep your content and your sanity in check.

Get the free guide

 

Video Guide

A Marketer's Guide to the Video Galaxy

This guide will explain how the right tools, and optimizing your video workflow can have a serious impact on internal cost savings, and increased sales.

Get the guide

 

Brand Guide

How to Make Youe Brand a Pillar of Strength

The simple strategies in this guide will help you tackle brand management successfully, one step at a time.

Get the guide

Recent

Are you ready for a DAM solution of your own? Get Started