How to update a JOINed tables using Codeigniter's Active Record?
Codeigniter active record doesn't allow to update a joined tables.
After trying various method and searching the solution, I have found the following solution which does the exactly same thing i.e. update the multiple join tables. By using following method, you can update multiple table using codeigniter active record.
After trying various method and searching the solution, I have found the following solution which does the exactly same thing i.e. update the multiple join tables. By using following method, you can update multiple table using codeigniter active record.
$this->db->set('a.firstname', 'Pekka'); $this->db->set('a.lastname', 'Kuronen'); $this->db->set('b.companyname', 'Suomi Oy'); $this->db->set('b.companyaddress', 'Mannerheimtie 123, Helsinki Suomi'); $this->db->where('a.id', 1); $this->db->where('a.id = b.id'); $this->db->update('table as a, table2 as b');
Thanks for sharing!, pretty useful
ReplyDeleteThis method will not work with CI3. I know this because I used it often in CI2. I do not have a replacement yet except maybe update_batch()
ReplyDeleteIs it work for more than two table ?
ReplyDeleteIt should work with many tables but you should correctly use join.
DeleteCan I use '$data' array for '$this->db->set()' method?
ReplyDeleteI tried .. $data array worked!!!
Deletehow to use in controller and model? i'm confused, update data in 3 tables.
ReplyDeletecan you help me please?