Zend 框架关系 - findDependentRowset
当我调用 findDependentRowset 方法时,返回的行集包含依赖表中的所有行,而不仅仅是与引用匹配的行集。
希望有人能够解释这一点,因为我假设 findDependentRowset 只会返回与我的“规则”匹配的行集?
我有以下 DbTable 模型:
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',
)
);
}
现在,当我执行以下命令时:(为了问题而简化)
$model = new Model_DbTable_Advertisement();
$rowSet = $model->fetchAll();
$row = $rowSet->current();
$dRow = $row->findDependentRowset('Model_DbTable_Image');
我希望 $dRow 仅包含与 $row 具有相同advertisementId 的“图像”,但我收到了图像表中的所有行。
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 explain 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该文档似乎说您可能错误地命名了第二个表的参考图中的某些元素。看看用“columns”和“refColumns”替换“column”和“refColumn”键,然后将字符串值放入单例数组中是否可以解决问题。
请参阅 http:// /framework.zend.com/manual/en/zend.db.table.relationships.html#zend.db.table.relationships.defining 了解更多信息
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