views:

75

answers:

1

Hi All,

Example:

class Products extends Zend_Db_Table_Abstract
{
    protected $_name = 'products';

    protected $_referenceMap    = array(
        'Bug' => array(
            'columns'           => array('bug_id'),
            'refTableClass'     => 'Bugs',
            'refColumns'        => array('bug_id')
        )
    );

}

$object = new Products();

$select = $object->select()->from()->Join('Bug');

Instead of defining the full join statement

A: 

As far as I can tell $_referenceMap is not used in that way. $_referenceMap defines the relationship that a table row has with other tables.

That's why the associated findDependentRowset(), findManyToManyRowset() and findParentRow() are found in Zend_db_Table_Row_Abstract. These methods create the Joins.

So to get the dependent rows from Bugs, using a select object, you would do something like this, assuming that Products has a one-to-many relationship with Bugs;

class Products extends Zend_Db_Table_Abstract
{
    protected $_name             = 'products';
    protected $_dependentTables  = array('Bugs');
}

class Bugs extends Zend_Db_Table_Abstract
{
    protected $_referenceMap = array(
        'Products' => array(
            'columns'            => array('bug_id')
            ,'refTableClass'     => 'Products'
            ,'refColumns'        => array('bug_id')
        )
    );
}

To get dependent rows you first have to fetch a parent row.

$products = new Products();

$productRow = $products->find(123)
                       ->current();

You can refine the join by using Zend_Db_Select

$select = $products->select()
                   ->where('foo_bar = ?', 'cheese')
                   ->limit(2);

Finally querying the dependent rows by passing in the select object instead instead of a rule key.

$bugRowset = $productRow->findDependentRowset('Bugs', 'Products', $select);

I think this will work, I'll have to check tomorrow morning.

gawpertron
You're absolutely right, found out this my self also :)
Phliplip