Пример #1
0
 /**
  * Delete from the database.
  *
  * @param MIDAS_GlobalDao $dao
  * @return true
  * @throws Zend_Exception
  */
 public function delete($dao)
 {
     if (!$dao->saved) {
         throw new Zend_Exception('The dao should be saved first ...');
     }
     if (!isset($this->_key) || !$this->_key) {
         $query = array();
         foreach ($this->_mainData as $name => $option) {
             if ($option['type'] == MIDAS_DATA) {
                 $query[$name . ' = ?'] = $dao->{$name};
             }
         }
         if (empty($query)) {
             throw new Zend_Exception('Huge error, you almost deleted everything');
         }
         parent::delete($query);
         $dao->saved = false;
         return true;
     }
     $key = $dao->getKey();
     if (!isset($key)) {
         throw new Zend_Exception('Unable to find the key');
     }
     parent::delete(array($this->_key . ' = ?' => $dao->getKey()));
     $key = $dao->_key;
     $dao->set($key, null);
     $dao->saved = false;
     return true;
 }