codeigniter-base-model
codeigniter-base-model copied to clipboard
After_delete callbacks
Hi,
I wanted to change the native "delete" returns, so that they return ($this->db->affected_rows() > 0).
This way, they return TRUE if anything was deleted, and FALSE if nothing was deleted. I think this is better than the default CI + mySQL methods (which is return TRUE if the "operation" was successful, even if nothing was deleted).
So I tried to do a $after_delete callback. However I've discovered that you cant alter the $result from a delete using callbacks.
So I changed lines 311, 326 and 339 from:
$this->_run_after_callbacks('delete', array( $id, $result ));
to
$result = $this->_run_after_callbacks('delete', array( $id, $result ));
Because $result is passed to the callback, you can just return the default $result, and keep your logic the same. Or you can change the $result in your callback, and alter the overall outcome.