I need a data mapping/repository solution and would like to avoid having to write my own.
Doctrine seems to fulfill all the requirements apart from one, but I just don't know how to do it.
I am working with a legacy database and I would like to have my domain objects completely unrelated to the database until we are able to phase out the old application part by part (which will take at least a year). That means I need a way to add fields from other tables to an entity.
Here is an example:
<?php
namespace Entities;
class Article
{
protected $id;
protected $name; // from article table
protected $description; // from article_info table, joined from article table
protected $stock; // from article_variation_info, joined from article_info table
...
}
The doctrine docs seem to indicate two possible solutions:
- Creating entities for all the tables and then using custom getters/setters to add a field to an entity
- Use native SQL to get the entity data and for each repository query (see here)
I would like to avoid the first option because I want to create a clean domain model for the new application free from old limitations/bad decisions from the past. Having to create entities for each table seems to be counterproductive here.
The second options seems a little better, but if I have to write all the SQL I might as well code my own PDO repositories and mappers instead.
Am I missing something or is doctrine just not the ideal solution for what I am trying to do?