开发者

Zend Framework Relationships - findDependentRowset

开发者 https://www.devze.com 2022-12-30 11:04 出处:网络
When I call the method findDependentRowset, the returning rowset contains all the rows in the dependent table, and not only the rowsets that matches the reference.

When I call the method findDependentRowset, the returning rowset contains all the rows in the dependent table, and not only the rowsets that matches the reference.

Hoping someone could exp开发者_StackOverflowlain this, since I was of the assumption that findDependentRowset would only return rowset matching my 'rule'?

I have the following DbTable Models:

class Model_DbTable_Advertisement extends Zend_Db_Table_Abstract
{
    protected $_name = 'Advertisements';
    protected $_primary = 'Id';

    protected $_dependentTables = array (
        'Model_DbTable_Image',
    );
}

class Model_DbTable_Image extends Zend_Db_Table_Abstract
{
    protected $_name = 'Images';
    protected $_primary = 'Id';

    protected $_referenceMap = array(
        'Images' => array(
            'column' => 'AdvertisementId',
            'refColumn' => 'Id',
            'refTableClass' => 'Model_DbTable_Advertisement',
        )
    );

}

Now when i execute the following: (Simplified for Question sake)

$model = new Model_DbTable_Advertisement();
$rowSet = $model->fetchAll();
$row = $rowSet->current();
$dRow = $row->findDependentRowset('Model_DbTable_Image');

I would expect $dRow to only contain 'Images' that has the same advertisementId as $row, but instead i receive all rows in the Images table.


The documentation seems to say that you may be misnaming some elements in your reference map for the second table. See if replacing the 'column' and 'refColumn' keys with 'columns' and 'refColumns', and then placing the string values into singleton arrays does the trick.

See http://framework.zend.com/manual/en/zend.db.table.relationships.html#zend.db.table.relationships.defining for more info

0

精彩评论

暂无评论...
验证码 换一张
取 消