从CodeIgniter中的不同表中删除行

bes*_*rld 4 php activerecord codeigniter

一点代码片段:

$this->db->where('id', $outfit_id);
$this->db->update('outfit_main',$data);

//Delete productsettings for specific outfit (They are added below with new values)
$this->db->where('outfit_id', $outfit_id);
$this->db->delete('outfit_products');

//Delete outfit_images for specific outfit as well. They are also added below
$this->db->where('outfit_id', $outfit_id);
$this->db->delete('outfit_images'); 
Run Code Online (Sandbox Code Playgroud)

我想做的是:

  1. 从outfit_main中删除行,其中id = $ outfit_id
  2. 从outfit_products中删除行,其中outfit_id = $ outfit_id
  3. 从outfit_images中删除行,其中outfit_id = $ outfit_id

但实际上当我添加最后两行时:

$this->db->where('outfit_id', $outfit_id);
$this->db->delete('outfit_images'); 
Run Code Online (Sandbox Code Playgroud)

*它也会删除outfit_main中的所有行.为什么?*

doi*_*tin 6

尝试将where子句与delete活动记录组合:

$this->db->delete('outfit_main', array('id' => $outfit_id));
$this->db->delete('outfit_products', array('outfit_id' => $outfit_id));
$this->db->delete('outfit_images', array('outfit_id' => $outfit_id));
Run Code Online (Sandbox Code Playgroud)