我有两种模式:
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子句的行集