findDependentRowset 返回所有行

发布于 2024-09-16 09:23:35 字数 1427 浏览 11 评论 0原文

我有这两个模型:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2024-09-23 09:23:35

哎呀。事实证明这是有效的,但无效的 HTML 隐藏了我期望的输出

Oops. It turns out this was working but invalid HTML was hiding the output i was expecting

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文