Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refactoring from ActiveRecord to DataMapper

Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the switch? I'm primarily interested in web based applications, but would like to know the challenges that accompany such a move in any environment.

like image 903
Owen Avatar asked Mar 02 '23 06:03

Owen


1 Answers

I really do like the ActiveRecord pattern for its simplicity. However, I have been moving away from it for larger web apps. I find that as an ActiveRecord based project becomes more complex the ActiveRecord objects become large and laden with too much code.

By introducing a Repository pattern (essentially a Data Mapper) the domain model classes become simpler and the data mapping / data access logic is kept separate.

Also, it is quite difficult (impossible?) to mock ActiveRecord objects because of their user of static methods.

like image 109
Mike Avatar answered Mar 15 '23 14:03

Mike