Update operation of an active Codeigniter record with a connection

This is a query that I am trying to execute using an 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 active recording:

 $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; } 

And this is the request that is actually being created:

 UPDATE `Customer_donations` cd SET `cd`.`amount` = '1', `cd`.`amount_verified` = '1' WHERE `i`.`invoice_id` = '13' 

Why doesn't this active write statement apply my join clause?

+7
source share
2 answers

How about the solution below? A little ugly, but he 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); 
+16
source

Even cleaner since the update takes the third parameter "where":

 $invoiceId = 13; $amount = 4; $data = array('cd.amount'=>$amount, 'cd.amount_verified'=>'1'); $this->db->update('Customer_donations cd join Invoices i on i.cd_id = cd.cd_id', $data, array('i.invoice_id' => $invoiceId)); 
+1
source

All Articles