1
votes

So I am developing an application using the Data Mapper design pattern but I am having some problems in handling relationships between database tables. I am not sure, and could not find any resource of how should I map my relations with the Data Mapper pattern.

Should I use referenceMap and dependentTables definitions in my DbTable classes or should I go with composition and instantiate a new class when I need it?

For example a blog post and it's author should be something like:

$blog->author = findDependentRowset($row)

or

$author = new Author();
$blog->author = $author->findAuthorById($authorId);
1

1 Answers

0
votes

In my opinion, the most 'Data Mapper related' way to implement the table relationships in Zend Framework is, as you point out, using referenceMap and dependentTables.

Depending on other factors (performance needs, complexity of your DB model...) you might want to be a bit less strict with the design pattern and implement the mapping only for the tables, implementing the relationship related queries yourself (by using the Zend_Select object provided by $this->getAdapter()->select() and some JOINs).

Hope that helps,