Active Record places persistence behavior on objects that represent database records. Data Mapper keeps persistence mapping in a separate layer. Neither approach is universally superior; the right trade-off depends on the complexity of the domain and the team's ability to maintain boundaries.
Active Record strengths and limits
Active Record can make common create, read, update and delete operations concise. It is convenient for CRUD-heavy applications. As business rules grow, model callbacks and implicit database access can make workflows difficult to trace and test.
Data Mapper strengths and limits
A Data Mapper separates domain objects from persistence mapping. This can protect complex business rules from database details, but introduces more mapping code and architectural decisions.
Choose based on change pressure
If the application mostly manages straightforward records, Active Record may be productive. If domain rules are complex, multiple storage mechanisms are expected or persistence must be isolated, a Data Mapper-style boundary may be worth the cost.
Keep transactions explicit
Whichever pattern is used, define transaction boundaries around complete use cases and test persistence behavior against the actual database engine.
Further reading
- Martin Fowler, Active Record: https://martinfowler.com/eaaCatalog/activeRecord.html
- Martin Fowler, Data Mapper: https://martinfowler.com/eaaCatalog/dataMapper.html