我为我的Grid表创建了一个资源模型,其中包含一个连接2表的自定义查询。CCD_ 1和CCD_。以下是我的查询
protected function _initSelect()
{
parent::_initSelect();
$this->getSelect()
->joinLeft(
['spt' => $this->getTable('sales_payment_transaction')],
'main_table.entity_id = spt.order_id',
['spt.created_at as date_paid']
)
->where('main_table.status in ("complete", "processing")')
->order('main_table.entity_id DESC');
$this->addFilterToMap('created_at', 'main_table.created_at');
return $this;
}
如您所见,在我的自定义列中,我添加了一个新列,即名称为date_paid
的spt.created_at
。此新列用于日期筛选。因此,每当我按日期筛选订单时,都会使用date_paid
作为参数。现在,当查看日志时,我得到这个错误
SELECT COUNT(*) FROM `sales_order` AS `main_table`
LEFT JOIN `sales_payment_transaction` AS `spt`
ON main_table.entity_id = spt.order_id
WHERE (main_table.status in ("complete", "processing"))
AND (`date_paid` >= '2021-01-03 00:00:00')
AND (`date_paid` <= '2021-10-03 22:59:59')
/// Column not found: 1054 Unknown column 'date_paid' in 'where clause'
它似乎认不出新栏目了。我可以知道如何正确构造这个查询吗?
您的报价似乎不在这里:
["spt.created_at as date_paid"]
应为:
['spt.created_at'作为'date_paid']