我正在为MySQL结果保湿:
public function getMiscdamage($id)
{
$sql = new Sql($this->dbAdapter);
$select = $sql->select('misc_damage');
$select->where(array('vehicle_id = ?' => $id))->order('date_added DESC');
$select->join('user','user.user_id = misc_damage.added_user_id', array('added_user_display_name' => 'display_name'), 'left');
$stmt = $sql->prepareStatementForSqlObject($select);
$result = $stmt->execute();
if ($result instanceof ResultInterface && $result->isQueryResult()) {
$resultSet = new HydratingResultSet(new \Zend\Stdlib\Hydrator\ClassMethods(), new \Application\Model\Miscdamage());
return $resultSet->initialize($result);
}
throw new \InvalidArgumentException("Vehicle with given ID:{$id} not found.");
}
查询具有LEFT连接,查询可以正常工作。但是当我在循环中var_dump
时,added_user_display_name`为null:
/var/www/zf-skeleton/module/Application/view/application/live/details.phtml:337:
object(Application\Model\Miscdamage)[662]
protected 'id' => string '100' (length=3)
protected 'vehicle_id' => string '8' (length=1)
protected 'added_user_id' => string '1' (length=1)
protected 'added_user_display_name' => null
protected 'description' => string 'dfgdggfdd' (length=9)
protected 'date_added' => string '2016-04-15 12:26:40' (length=19)
protected 'date_repaired' => null
protected 'repaired_user_id' => null
protected 'status' => string '0' (length=1)
如何使用左连接和保湿器?任何帮助表示赞赏。
答案 0 :(得分:0)
您的sql结果是来自功能需要数据的响应。因此,您应该使用专为此功能需求而构建的定制保湿器。这种保湿剂通常是一种聚合剂保湿剂,它使用多个保湿剂来构建定制模型。你应该看看