Codeigniter database reset cache query after one detetion

I have a function which allow me to delete a row on a table. But the problem is that, for database integrity, I have to delete another row on another table that is in relation with the record I want to delete. This is my function :

public function delete($tab)
        $this->db->where('id', $tab['id']);
        $this->db->delete('agent', $tab);
        $this->db->where('id_agent', $tab['id']);
        $this->db->delete('agent_vendeuse', $tab);

I have an error database error on my function :

DELETE FROM `agent_vendeuse` WHERE `id_agent` = '2' AND `id` = '2'

Which means that after I affected the new index ‘id_agent’ for the where clause, the previous one ‘id’ is still in cache.

I guess I have to clean the case after the first deletion but how to write it ?

Source: stackoverflow-php