带有连接的Codeigniter活动记录更新

use*_*127 3 php mysql activerecord codeigniter sql-update

我有两张桌子:

table1:id,user_id,poll_id,options_id

table2:id,poll_id,votes

列投票是一个整数,我想通过将表与一些where子句连接来更改该值:

$this->db
->set('votes', 'votes - 1', FALSE)
->join('table1', 'poll_votes.options_id = table2.id')
->where('poll_id', $row)
->where('user_id', $id)
->update('table2');
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Error Number: 1054
Unknown column 'user_id' in 'where clause'
UPDATE `table2` SET votes = votes - 1 WHERE `poll_id` = '9' AND `user_id` = '1'

M K*_*aid 9

试试这个:

$this->db->set('votes', 'votes - 1', FALSE)
$this->db->where('table1.user_id',$id);
$this->db->where('table2.poll_id',$row);
$this->db->update('table1 join table2 ON table1.poll_id= table2.poll_id');
Run Code Online (Sandbox Code Playgroud)