Pragmatism in the real world

Ralph Schindler: Composite Rowsets For Many-To-Many Relationships Via Zend_Db_Table

Ralph has just posted an excellent article on how many to many relationships work with Zend_Db_Table:

Basically, I’ve created a single class that effectively take the place of Zend_Db_Table_Row::findManyToManyRowset() for the purposes of creating an iterable rowset that allows access to both the target many-to-many rowset as well as the junction rowset. This solution is called a Composite Rowset. In this solution, both rowsets (iterators) are kept in sync with one another. This proves to be an ideal solution in a couple of ways. First, it will produce consistent row objects that are explicitly tied to a row in a database. Second, the cost of creating this composite rowset is at the expense of 2 queries: the original many-to-many query and a similar query to retrieve the junction rowset. This is ideal since previously, to get the junction data, findDependentRowset() would have had to been called on each row within the rowset produced by the Zend_Db_Table_Row::findManyToManyRowset().

He then goes on to show the API for the Composite Rowset class and provides an example of usage.

If you’re using Zend_Db_Table at all, have a read.

My favourite text in the article is however this:

Over the past several years of working on Zend Framework, I’ve noticed the developer population at large is really good at finding undocumented and previously unthought-of use-cases of Zend Framework components. These use-cases, while sometimes “inventive” to say the least- are also sometimes blatant misuses of a component.

That’s one of the pleasures of providing code to the world :)