/**
  * Updates existing entry
  *
  * @param Tinebase_Record_Interface $_record
  * @throws Tinebase_Exception_Record_Validation|Tinebase_Exception_InvalidArgument
  * @return Tinebase_Record_Interface Record|NULL
  */
 public function update(Tinebase_Record_Interface $_record)
 {
     $identifier = $_record->getIdProperty();
     if (!$_record instanceof $this->_modelName) {
         throw new Tinebase_Exception_InvalidArgument('invalid model type: $_record is instance of "' . get_class($_record) . '". but should be instance of ' . $this->_modelName);
     }
     /** @var Tinebase_Record_Interface $_record */
     $_record->isValid(TRUE);
     $id = $_record->getId();
     $recordArray = $this->_recordToRawData($_record);
     $recordArray = array_intersect_key($recordArray, $this->getSchema());
     $this->_prepareData($recordArray);
     $where = array($this->_db->quoteInto($this->_db->quoteIdentifier($identifier) . ' = ?', $id));
     $this->_db->update($this->_tablePrefix . $this->_tableName, $recordArray, $where);
     // update custom fields
     if ($_record->has('customfields')) {
         Tinebase_CustomField::getInstance()->saveRecordCustomFields($_record);
     }
     $this->_updateForeignKeys('update', $_record);
     $result = $this->get($id, true);
     return $result;
 }