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);
// Here the query is "DELETE from agent WHERE id = $tab['id']"
$this->db->where('id_agent', $tab['id']);
$this->db->delete('agent_vendeuse', $tab);
// Here the query gives "Delete from agent_vendeuse WHERE id_agent= $tab['id'] AND id=$tab['id'];" Which is where the error comes from
}
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.
The $tab variable is coming from $_POST of my form. I just changed its name in function.
I guess I have to clean the cache after the first deletion but how to write it ?