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.
source share