public function save()
{
$this->beforeSave();
/**
* If the primary key is empty, this is an INSERT of a new row.
* Otherwise check primary key updated or not, if it changed - INSERT
* otherwise UPDATE
*/
if (!sizeof(array_filter($this->getPrimaryKey()))) {
$result = $this->doInsert();
} elseif (sizeof(array_diff_assoc($this->getPrimaryKey(), $this->clean))) {
$result = $this->doInsert();
} else {
$result = $this->doUpdate();
}
$this->afterSave();
return $result;
}