如何在ZF2中使用having()子句?
网上几乎没有例子如何准备正确的选择对象.
我有这样的查询:
SELECT root_schema_id as `schema_id`
FROM `standard_specific_root_schemas`
WHERE `vehicle_id` IN (".implode(",",$vehiclesIds).")
GROUP BY `schema_id`, rootSubGroup_id HAVING count(*)=".$noOfVehicles
Run Code Online (Sandbox Code Playgroud)
而我正试图在ZF2中运行它:
public function getVehicleWithinCommonRootSubgroupInSpecific($vehiclesIds)
{
$where = new Where();
$where->in('vehicle_id', $vehiclesIds);
$having = new Having('count(*) = '.count($vehiclesIds));
$rowset = $this->tableGateway->select(function (Select $select) use ($where, $having) {
$select
->where($where)
->having($having);
});
if (!$rowset) {
throw new \Exception("Could not find schemas for group $groupId");
}
return $rowset;
}
Run Code Online (Sandbox Code Playgroud)
当然,ZF2中的那部分尚未完成,因为我想检查它是否先工作.我尝试过几种方法来提供params来获取方法,但是一切都会产生错误.
请帮忙,我很绝望......