如何以CakePHP的方式进行此查询?
SELECT *
FROM uploaded_sales us, sales s
WHERE us.item_id = s.audience_id
item_id
表的uploaded_sales
列不是其主键。
audience_id
表的sales
列也不是它的主键。
我在我的模型上尝试了这个,我没有收到任何错误,但仍然将sales
作为空白返回:
$reports = $this->find('all',
array(
'joins' => array(
array(
'table' => 'sales',
'alias' => 'Sale',
'type' => 'left',
'conditions' => array('Sale.audience_id' => 'UploadedSale.item_id')
)),
'conditions' => array(
'UploadedSale.month' => $month,
'UploadedSale.year' => $year,
'UploadedSale.company_id' => $company_id,
'UploadedSale.item_type' => $item_type
),
'fields' => $fields
));
return $reports;
答案 0 :(得分:1)