現在、次のコード スニペットがあります。
$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
。
私はそれを変更できることを知っています。同じ量のクエリを残しますが、削除ではなく更新で、これをより少ないクエリに縮小できることを望んでいましたか?