Can I UPDATE a JOINed table using Active Record Active Code?

Here is what I would like to do

function edit_save($data, $post_id, $user_id) { $this->db->where('post.user_id', $user_id); $this->db->where('post.post_id', $post_id); $this->db->join('data', 'post.data_id_fk = data.data_id', 'left'); $this->db->update('post', $data); } 

The "post" column must be connected to the "data".

When I run above, I get an SQL error saying that one of the fields from the "data" table was not found.

Any suggestions?

ADDITIONAL INFORMATION

This is a generated SQL query.

 UPDATE `post` SET `data_value` = '111', `data_date` = '2012-02-13', `post_text` = '111' WHERE `post_stream_id` = '5' AND `post_id` = '18' 

This is mistake

 Unknown column 'data_value' in 'field list' 

It does not show the JOIN instruction.

+4
source share
1 answer

Try this active write request for updates using connections:

 function edit_save($data, $post_id, $user_id) { $this->db->set($data) $this->db->where('post.user_id', $user_id); $this->db->where('post.post_id', $post_id); $this->db->where('post.data_id_fk = data.data_id'); $this->db->update('post, data'); } 
+3
source

Source: https://habr.com/ru/post/1396095/


All Articles