/**
* Delete record(s) from this table, optionally extending by specifying a $Join to
* delete adjoining data from both
*
* @param ifx_Model $JoinObject
* @param mixed $JoinType
*
* @return bool
*/
public final function delete(ifx_Model $JoinObject = null, $JoinType = 'INNER')
{
if (!empty($JoinObject) and is_a($JoinObject, get_class())) {
//Generate the join
$this->_forge_join($JoinObject, $JoinType);
//Generate the query
$SQL = 'DELETE ' . $JoinObject->_table() . ', ' . $this->_table() . ' FROM ' . $this->_forged_join();
//If this object was loaded, limit by this record
if ($this->is_loaded()) {
$this->db->where($this->_table() . '.' . $this->_id(), $this->id());
}
//If the join object was loaded, limit the query by the loaded record
if ($JoinObject->is_loaded()) {
$this->db->where($JoinObject->_table() . '.' . $JoinObject->_id(), $JoinObject->id());
}
//Get the WHERE portion from CI_DB_AR
$Where = implode(' ', $this->db->ar_where);
$this->db->ar_where = array();
//Join the WHERE, if any
$SQL .= !empty($Where) ? ' WHERE ' . $Where : '';
//Run the query
$this->db->query($SQL);
//Reset the forged table for next time
$this->_clear_forged_join();
} elseif ($this->is_loaded()) {
//We only allow deletes for a loaded record, to avoid whole table deletes
$this->db->where($this->_id(), $this->id());
$this->db->delete($this->_table());
}
if ($this->db->affected_rows() >= 1) {
$this->_data = array();
return true;
}
return false;
}