Reader small image

You're reading from  Layered Design for Ruby on Rails Applications

Product typeBook
Published inAug 2023
Reading LevelIntermediate
PublisherPackt
ISBN-139781801813785
Edition1st Edition
Languages
Right arrow
Author (1)
Vladimir Dementyev
Vladimir Dementyev
author image
Vladimir Dementyev

Vladimir Dementyev has been working on web applications for more than 10 years and launched his first Ruby on Rails project back in 2014. Since then, he has been working on a dozen of Rails web applications, used by hundreds of millions of customers, monolithic or component-based, following the Rails way or trying to swim against the current. He has been an active member of Rails open-source community since 2015, becoming a regular Rails contributor, a RailsConf speaker, and the author of dozens of gems, including AnyCable, TestProf, and Action Policy to name a few. For his work on the Ruby Next project, the author got the Fukuoka Ruby Award for outstanding performance in 2021. Currently, he's leading the backend developers' team at Evil Martians, helping dozens of web projects around the world build better software.
Read more about Vladimir Dementyev

Right arrow

Separating domain and persistence with repositories

In Chapter 2, Active Models and Records, we discussed two object-relational mapping abstractions, Active Record and Data Mapper, and their differences. Rails obviously goes with the first approach, but that doesn’t mean we cannot derail and use Data Mapper concepts in our code.

To recall, the main difference between Active Record and Data Mapper is that Data Mapper separates models from persistence: models are just enhanced data containers, and other objects are used for querying and storing data (repositories and relations). Thus, there is a clear separation between the domain layer and domain services. This separation gives you more control over data access and transformation at the cost of losing Active Record’s (the library’s) simplicity.

Usually, switching to the Data Mapper paradigm in Ruby on Rails applications comes along with migrating to some other ORM instead of Active Record – for instance...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Layered Design for Ruby on Rails Applications
Published in: Aug 2023Publisher: PacktISBN-13: 9781801813785

Author (1)

author image
Vladimir Dementyev

Vladimir Dementyev has been working on web applications for more than 10 years and launched his first Ruby on Rails project back in 2014. Since then, he has been working on a dozen of Rails web applications, used by hundreds of millions of customers, monolithic or component-based, following the Rails way or trying to swim against the current. He has been an active member of Rails open-source community since 2015, becoming a regular Rails contributor, a RailsConf speaker, and the author of dozens of gems, including AnyCable, TestProf, and Action Policy to name a few. For his work on the Ruby Next project, the author got the Fukuoka Ruby Award for outstanding performance in 2021. Currently, he's leading the backend developers' team at Evil Martians, helping dozens of web projects around the world build better software.
Read more about Vladimir Dementyev