protected function _update() { if (empty($this->_changed)) { return $this; } if ($this->_read_only) { return $this; } $vr = $this->_version_coloumn_reason; $old_item = ORM::factory($this->_object_name, $this->pk()); $data = $old_item->as_array(); $data[$vr] = $this->{$vr}; $data[$this->_version_of] = $data[$this->_primary_key]; unset($data[$this->_primary_key]); $result = DB::insert($this->_version_table_name)->columns(array_keys($data))->values(array_values($data))->execute($this->_db); if ($result) { if ($this->empty_pk()) { // $result is array(insert_id, total_rows) $this->_object[$this->_primary_key] = $result[0]; } } else { throw "Error saving"; } unset($data[$this->_version_coloumn_reason]); $v = $this->_version_coloumn_name; $this->{$v} += 1; if (is_array($this->_created_column)) { // Fill the created column $column = $this->_created_column['column']; $format = $this->_created_column['format']; $this->{$column} = $this->_object[$column] = $format === TRUE ? time() : date($format); } parent::_update(); }