Refactoring with ActiveRecord on DataMapper

Have you implemented ActiveRecord on a DataMapper template? What conditions prompted the switch? I am primarily interested in web applications, but I would like to know the problems that accompany such a step in any environment.

+4
source share
3 answers

I really like the ActiveRecord template for its simplicity. However, I moved away from it for larger web applications. I believe that as an ActiveRecord-based project gets more complex, ActiveRecord objects get large and load with more code.

By introducing a repository template (essentially a Data Mapper), the domain model classes become simpler and the data access / data access logic is stored separately.

It is also quite difficult (impossible?) To mock ActiveRecord objects due to their user static methods.

+7
source

I use the framework that provides the Data Gateway and Row Data Gateway as built-in classes that are easy to use, because all I have to specify is the primary key (if not just the "id"), and the name of the table (if it doesn't match class name). However, I recently discovered during the refactoring process that these patterns begin to worsen the moment when a more complex mapping between the domain and the database should occur.

For example, I am currently reorganizing the code for a single website to use the Data Mapper so that I can use the Single Table Inheritance (uses Inheritance Mapping). In principle, at any time the relationship between the database and the domain becomes more complex than one-to-one, I would think a lot about using Data Mappers.

+1
source

I wrote an integrated build system sitting on top of PDE-Build using camping . I originally used ActiveRecord, but I needed non-blocking thread-safe database access, so I switched to using Data Mapper.

I had my own share of sadness from mistakes, but the latest versions seem pretty stable.

0
source

Source: https://habr.com/ru/post/1277553/


All Articles