这是我试图通过事件记录实现的查询:
UPDATE `Customer_donations` cd
join Invoices i on i.cd_id = cd.cd_id
set cd.amount = '4', cd.amount_verified = '1'
WHERE i.invoice_id = '13';
这是我对事件记录的尝试:
$data = array('cd.amount'=>$amount, 'cd.amount_verified'=>'1');
$this->db->join('Invoices i', 'i.cd_id = cd.cd_id')
->where('i.invoice_id', $invoiceId);
// update the table with the new data
if($this->db->update('Customer_donations cd', $data)) {
return true;
}
这是实际生成的查询:
UPDATE `Customer_donations` cd
SET `cd`.`amount` = '1', `cd`.`amount_verified` = '1'
WHERE `i`.`invoice_id` = '13'
为什么这个事件记录语句没有应用我的连接子句?
最佳答案
下面的解决方案怎么样?有点难看,但它达到了您在问题中的预期。
$invoiceId = 13;
$amount = 4;
$data = array('cd.amount'=>$amount, 'cd.amount_verified'=>'1');
$this->db->where('i.invoice_id', $invoiceId);
$this->db->update('Customer_donations cd join Invoices i on i.cd_id = cd.cd_id', $data);
关于php - 带有连接的 Codeigniter 事件记录更新语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9578253/