ZF-7018: Zend_Db_Table should fetch related objects

Description

Many users ask for how to write a join request with Zend_Db_Table->select(). For now it is not possible to join foreign column to a table select statement unless you call setIntegrityCheck(false). Even so, the result is having one corrupted Zend_Db_Table_Row instance with all column. I expected to have a non corrupted Zend_Db_Table_Row with the foreign attribute being a reference to a second non corrupted Zend_Db_Table_Row.

Let have an exemple : We have to tables : Bugs(bug_id, title, author_id) and Authors(author_id, name). I want to fetch all Bug table entries.

I can write :


$bug = new DbTable_Bugs();
$bugs = $bug->fetchAll();
for each ($bugs as $bugRow)  {
    $bugRow->findParentRow('Author');
}

But, this way I will do 1 + n queries to the database : 1 for the fetchAll query, n being every findParentRow queries. The solution would be something like :


$bugs = $bug->fetchAllJoinAuthor();

and then findParentRow do not require any other queries, every rows needed whould have already been created and linked together.

Today I am nearly sure this feature does not exist yet (but I may be wrong). I think that Zend_Db_Table_Row do not support foreign rows. It would be great if Zend_Db could run the same as Propel does in the following exemple (my inspiration for this thread) : [http://propel.phpdb.org/trac/wiki/…]

Comments

I made up my mind and found a Component proposal on the wiki which is an answer to my problem : http://framework.zend.com/wiki/display/…