public function save($ignore = false)
{
$query = array();
// remove any expression fields as they are already baked into the query
$values = array_values(array_diff_key($this->_dirty_fields, $this->_expr_fields));
if ($ignore) {
$query = $this->_build_insert_update();
$values = array_merge($values, $values);
} else {
if (!$this->_is_new) {
// UPDATE
// If there are no dirty values, do nothing
if (empty($values) && empty($this->_expr_fields)) {
return true;
}
$query = $this->_build_update();
$values[] = $this->id();
} else {
// INSERT
$query = $this->_build_insert();
}
}
$success = self::_execute($query, $values, $this->_connection_name);
// If we've just inserted a new record, set the ID of this object
if ($this->_is_new) {
$this->_is_new = false;
if (!$this->id()) {
if (self::$_db[$this->_connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') {
$this->_data[$this->_get_id_column_name()] = self::get_last_statement()->fetchColumn();
} else {
$this->_data[$this->_get_id_column_name()] = self::$_db[$this->_connection_name]->lastInsertId();
}
}
}
$this->clear_cache();
$this->_dirty_fields = $this->_expr_fields = array();
return $success;
}