我们目前有这个代码片段:
$this->db->where('id', $id)->delete($this->table);
$this->db->where('product_id', $id)->delete($this->clink);
$this->db->where('product_id', $id)->delete($this->tlink);
$variants = $this->db->select('id')->from($this->vlink)->where('product_id', $id)->get();
if ($variants->num_rows() !== 0) {
//turns array(array('id' => 1), array('id' => 2)) into array(1,2)
$variants = $variants->result_array();
foreach ($variants as &$v) {
$v = $v['id'];
}
$this->db->where('product_id', $id)->delete($this->vlink);
$this->db->where_in('variant_id', $variants)->delete('cart_variant_values');
$this->db->where_in('variant_id', $variants)->delete('cart_variant_images');
$this->db->where_in('variant_id', $variants)->delete('cart_variant_documents');
}
这转化为:
delete from $this->table where id = $id
delete from $this->clink where product_id = $id
delete from $this->tlink where product_id = $id
$variants = select id from $this->vlink where product_id = $id //e.g. (1,2)
delete from $this->vlink where product_id = $id
delete from cart_variant_values where variant_id in $variants
delete from cart_variant_images where variant_id in $variants
delete from cart_variant_documents where variant_id in $variants
现在我需要修改代码,而不是删除所有行,而是在所有行上设置end_date
列。
我知道我可以修改它。留下相同数量的查询,但我希望作为更新而不是删除我可以将其缩小为更少的查询?