ORM… WTF???

What is ORM and what is not? Let’s repeat basic terms so we are on the same page before we dive into the object-relational mapping.

Relational Model

When we model data, we often think of the entity-relational model and it is fine. ER model is an abstraction based on the relational model and still focuses on data.

Object Model

Relational Database

Object-relational mapping

ORM is not about mapping fields, that would be easy. It is about mapping the object model to the relational model, and that is a difficult task. We have to fully understand both models and then we can start finding ways to map them. We usually find mapping problems that force us to do trade-offs in both models.

And that is the object-relational mapping — no more, no less. Mapping is pretty difficult, and maintain two models plus maintain the mapping is also a challenge. ORM library usually cannot do everything we imagine, it is just a fact we have to face.

Requirements

We must need a relational database. If we don’t need the relational database, we don’t have to map objects and our work is much easier.

Common misuses

ORM not-Responsibility

ORM shouldn’t be used for reading. It isn’t meant to be reading effective and it isn’t its responsibility. If we need to read information fast, we have to use fast reading techniques, not ORM.

No Object Model

If we try objects anyway, we end up with an anemic model. ORM becomes a stone that pulls us underwater. Everything becomes horribly slow and ORM will only make problems.

We can live without the ORM. We can have only one relational model in the database. We can query it, work with data. We don’t need to bother with objects and difficult mapping.

No Need for Relational Database

Then we don’t have to bother with relation model and mapping. We can store objects as they are in a NoSQL database. Choosing the database can take time but it pays itself.

TL;DR

Use ORM only if we need to. Handling two models and mapping is difficult.

References

Wikipedia contributors. Class-based programming. Wikipedia, The Free Encyclopedia [online]. 2018 [2018–01–23]. Available: https://en.wikipedia.org/wiki/Class-based_programming.

Wikipedia contributors. Object-oriented programming. Wikipedia, The Free Encyclopedia [online]. 2018 [2018–01–23]. Available: https://en.wikipedia.org/wiki/Object-oriented_programming.

Wikipedia contributors. Relational database. Wikipedia, The Free Encyclopedia [online]. 2018 [2018–01–23]. Available: https://en.wikipedia.org/wiki/Relational_database.

Wikipedia contributors. Relational model. Wikipedia, The Free Encyclopedia [online]. 2018 [2018–01–23]. Available: https://en.wikipedia.org/wiki/Relational_model.

Contact

--

--

Developer interested in Domain-Driven Design & Modeling

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store