Seeking some best practice advice. Basically I have a large entity that consists of various properties where some properties are other entities.
What is the best practice of "instantiating" the big entity in my datamapper? Do I call the other mappers for the other entities inside my "main" mapper? Example, I have an entity "Big" which consists of various properties where the "customer" property is a customer entity, is this the best way todo it?
class BigMapper{
//Find and return a BigEntity
function find($id){
$customerMapper = new CustomerMapper($this->db);
$customer = $customerMapper->findByBigEntityId($id);
$bigRow = $this->db->fetchRow('SELECT * FROM big WHERE id = ?', $id);
$bigRow['customer'] = $customer; //This line feels sort of ugly.... and then:
return( new EntityBig($bigRow) );
}
}
I have seen solutions where people instantiate the other mappers in the service layer and then sort of validate each entity by itself, and finally combine them all etc, but I'm really not sure what is the best way of "building" a large entity based on several other entities.
Any comment or help appreciated, thanks!