Hi,
I have two database tables (lets call them A and B) with many-to-many bridge table (AB). I have written Zend_Db_Table models for all three tables.
I have an A_Row object I extracted from the database using for example Zend_Db_Row::find method. Now I need get print a table of all rows, which are in relationship with this row. The problem is I need to have this table paginated, but the table is rendered using a method of B_Rowset.
I can see two options (if I want to use Zend_Paginator)
1) Use Zend_Paginator_Adapter_Iterator to paginate the rowset returned by findManyToManyRowset. This would look like this:
$b_rowset = $a_row->findManyToManyRowset('B_Table', 'AB_Table');
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Iterator($b_rowset));
However, there are two problems:
a) Whole result set (not only items on the page) is fetched.
b) I use a method of B_Rowset to render the table HTML, so I would have to convert the results back into result set.
This solution seems a little too ugly.
2) Build the Zend_Db_Table_Select manually and use Zend_Paginator_Adapter_DbTableSelect.
But building multi-table queries with Zend_Db_Table_Select is very unpretty (and the results need to be converted into B_Rowset). I would likely end up with 50 or so lines of messy code.
I could use either method (and I would likely be done faster than writing this post), but I want to see some opinions, how to solve this nicely (since I expect to encounter this scenario again and again).