您好我想在报表模型中加入2个表Reports和ReportResults
$report = $this->find('first', array(
'joins' => array(
array(
'table' => 'report_results',
'alias' => 'rr',
'type' => 'INNER',
'fields' => array(
"Report.*", "rr.*"
),
'conditions' => array(
"rr.report_id = {$this->alias}.id",
"{$this->alias}.status" => Report::STATUS_GENERATED,
"{$this->alias}.start_day = CURDATE() - INTERVAL 3 DAY",
)
)
),
'order' => array("rr.total DESC")
));
我的问题是只返回报告表字段。它似乎没有将字段部分纳入查询。最初我没有指定字段,但是当我指定它们或尝试限制仅返回少量报告字段的字段时,它仍然返回整个集合。
有人可以指出我可能遗失或做错了吗?
答案 0 :(得分:0)
典型!在我发布问题之前,我花了很长时间环顾四周,当我发布它时,我找到了答案。
因此,通过将字段移出连接,它可以正常工作
$report = $this->find('first', array(
'joins' => array(
array(
'table' => 'report_results',
'alias' => 'rr',
'type' => 'INNER',
'conditions' => array(
"rr.report_id = {$this->alias}.id",
"{$this->alias}.status" => Report::STATUS_GENERATED,
"{$this->alias}.start_day = CURDATE() - INTERVAL 3 DAY",
)
)
),
'fields' => array(
"Report.*", "rr.*"
)
'order' => array("rr.total DESC")
));