SQL加入ZF3表达式 - ResultSet不给予加入的列
问题描述:
我试图从第二个表中获取标题(通过左连接),但是我的结果集未传递连接表的列。SQL加入ZF3表达式 - ResultSet不给予加入的列
这是我TableGateway看起来像:
public function fetchCourseListWithStudyprogram()
{
$select = $this->getSql()->select();
$select->where->equalTo('course_active', 'Y');
$select->join('studyprogram', 'studyprogram.studyprogram_id = course.studyprogram_id', ['studyprogram_title'], $select::JOIN_LEFT);
$resultSet = $this->selectWith($select);
var_dump($resultSet);
return $resultSet->toArray();
}
该声明得到构造,因为它应该是:
public 'queryString' => string 'SELECT `course`.*, `studyprogram`.`studyprogram_title` AS `studyprogram_title` FROM `course` LEFT JOIN `studyprogram` ON `studyprogram`.`studyprogram_id` = `course`.`studyprogram_id` WHERE `course_active` = :where1' (length=214)
当它会得到结果,却忽视了“studyprogram_title”列,我猜是因为给定的resultSet(带有CourseEntity绑定)
有没有什么方法可以显示studyprogram_title而不将其添加到CourseEntity中?它并不是真正的一部分,所以我想如果我在那里添加它,它就会变脏。
答
有一种方法可以处理模型中的两个表格。
如果您想要直接连接两个表,而不是为每个表指定tablegateway
那么会引发问题。这意味着您不能将resultset
设置为数组,因为在这种情况下,您没有为其他表使用resultsetprototype
,就像您尝试加入两个表的那个(当前模型)一样。
你可以看看这个answer!