是否有可能使用codeigniter的活动记录更新连接表? [英] Is it possible to UPDATE a JOINed table using Codeigniter's Active Record?
本文介绍了是否有可能使用codeigniter的活动记录更新连接表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我想要做的。
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' table needs to be left-joined with 'data'.
当我运行上面我得到一个SQL错误,指出没有找到从数据表中的字段之一。
When I run the above I get a SQL error saying that one of the fields from the 'data' table is not found.
有什么建议?
更多信息
这是生成的SQL查询
UPDATE `post`
SET `data_value` = '111', `data_date` = '2012-02-13', `post_text` = '111'
WHERE `post_stream_id` = '5'
AND `post_id` = '18'
这是错误
Unknown column 'data_value' in 'field list'
它不显示的JOIN语句。
It doesn't show the JOIN statement.
推荐答案
试试这个活动记录查询与更新联接:
Try this active record query for update with joins:
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');
}
这篇关于是否有可能使用codeigniter的活动记录更新连接表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文