Codeigniter活动记录更新语句与联接 [英] Codeigniter active record update statement with a join
本文介绍了Codeigniter活动记录更新语句与联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我想通过活动记录实现的查询:
This is the query that i'm trying to achieve via active record:
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';
这是我在活动记录中的尝试:
This is my attempt at the active record:
$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'
记录语句不应用我的连接子句?
Why is this active record statement not applying my join clause?
推荐答案
有点丑,但它实现了你的期望在你的问题。
How about the solution below? A bit ugly but it achieved what you expected in your question.
$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);
这篇关于Codeigniter活动记录更新语句与联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文