我创建了sql查询,工作正常。
但是我想以cakephp格式转换这个sql查询。
我尝试在cakephp中转换此查询,但
我不了解如何在条件分组的情况下应用。
我只需要选择此列u_data.lane_id AS LaneId,origin_city.pcode AS origin_pcode,dest_city.pcode AS dest_pcode .... 不是表中的所有列。
请帮助我这样做。
$options['conditions'] = array(
'CustomerRoute.portfolio_id' => '".$_SESSION["portfolioid"]."'
);
$content = $this->Customer->find('all', $options);
答案 0 :(得分:2)
您只需在$ options中定义“group”和“fields” -
而不是$ _SESSION,你应该坚持惯例并使用$ this-> Session-> read。
//Eg: $_SESSION["portfolioid"] can be replaced with $this->Session->read("portfolioid")
$options['conditions'] = array(
"CustomerRoute.portfolio_id" => $this->Session->read("portfolioid"),
"u_data.supplier_id" => $this->Session->read("supplierid")
);
$options['fields'] = array(
"u_data.lane_id AS LaneId",
"origin_city.pcode AS origin_pcode",
"dest_city.pcode AS dest_pcode"
); // Add this
$options['group'] = array('CustomerRoute.id'); // Add this
$content = $this->Customer->find('all', $options);
这应该可以满足您的需求。
和平!的xD