findDependentRowset 返回所有行
我有这两个模型:
class Application_Model_List extends Zend_Db_Table_Abstract
{
protected $_name = 'list';
protected $_primary = 'list_id';
protected $_dependentTables = array('Application_Model_Task');
public function getUserLists($user)
{
$select = $this->select()->from($this->_name)->where('list_user = ?',$user);
return $this->fetchAll($select);
}
}
我
class Application_Model_Task extends Zend_Db_Table_Abstract
{
protected $_name = 'task';
protected $_primary = 'task_id';
protected $_referenceMap = array(
'List' => array(
'columns' => 'task_list_id',
'refTableClass' => 'Application_Model_List',
'refColumns' => 'list_id'
)
);
}
在我的控制器中调用 getUserLists
,如下所示:
public function indexAction()
{
$lists = new Application_Model_List();
$userLists = $lists->getUserLists(1);
$this->view->lists = $userLists;
}
并将其传递到我的视图,然后调用 findDependentRowset
像这样:
foreach($this->lists as $list){
echo $list->list_title;
$tasks = $list->findDependentRowset('Application_Model_Task');
foreach($tasks as $task){
echo $task->task_title;
}
}
但问题是它输出所有来自从属表的行集,而不仅仅是与 where 子句匹配的行集
I have these two models:
class Application_Model_List extends Zend_Db_Table_Abstract
{
protected $_name = 'list';
protected $_primary = 'list_id';
protected $_dependentTables = array('Application_Model_Task');
public function getUserLists($user)
{
$select = $this->select()->from($this->_name)->where('list_user = ?',$user);
return $this->fetchAll($select);
}
}
and
class Application_Model_Task extends Zend_Db_Table_Abstract
{
protected $_name = 'task';
protected $_primary = 'task_id';
protected $_referenceMap = array(
'List' => array(
'columns' => 'task_list_id',
'refTableClass' => 'Application_Model_List',
'refColumns' => 'list_id'
)
);
}
I call getUserLists
within my controller like this:
public function indexAction()
{
$lists = new Application_Model_List();
$userLists = $lists->getUserLists(1);
$this->view->lists = $userLists;
}
and pass it to my view and then call findDependentRowset
like this:
foreach($this->lists as $list){
echo $list->list_title;
$tasks = $list->findDependentRowset('Application_Model_Task');
foreach($tasks as $task){
echo $task->task_title;
}
}
but the problem is it outputs all rowsets from the dependent table, not just the ones matching the where clause
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哎呀。事实证明这是有效的,但无效的 HTML 隐藏了我期望的输出
Oops. It turns out this was working but invalid HTML was hiding the output i was expecting