/**
  * Delete this object from the database
  *
  * This will also handle deletion of all dependent objects, and any join relationships
  * (but not the joined objects themselves). If you do not require any complex 
  * deletion like this, the feel free to use the {@link SimpleQuery::create()} method to 
  * do a quick and simple delete operation, but make sure to call the 
  * {@link clearQueryCache()} method afterwards, like this:
  *
  * <code>
  * $book = new Book();
  * SimpleQuery::create('DELETE FROM '.$book->tableName().' 
  *                WHERE book_id = '.Query::clean(Application::param('book_id')));
  * $book->clearQueryCache();
  * </code>
  *
  * @access public
  * @see save,deleteLater,purge
  */
 public function delete($clear = false)
 {
     if (is_object($this->super_object)) {
         throw new Exception('You called delete() on a DbObject that has a super object (a generalised object) present. Either don\'t call also(\'' . $this->superObject()->getClass() . '\') when building the query, or call delete() on the super object. eg. $specialised->superObject()->delete()');
     }
     if ($this->db_clause || $clear || $this->id()) {
         if ($this->read() || $clear || $this->id()) {
             $this->clearAllJoins();
             $this->clearAllSupported();
             foreach ($this->existing_objects as $class => $objects) {
                 foreach ($objects as $key => $obj) {
                     $this->deleteObject($obj);
                 }
             }
             $this->existing_objects = array();
             $query = new DeleteQuery($this->tableName());
             $query->setClause($this->uniqueClause());
             $query->doQuery();
             $this->purge();
             $this->clearQueryCache();
         }
     } else {
         throw new Exception('You cannot call delete on a DbObject if you have not added conditions to it using the clause() method. If you wish to delete all instances of a particular object, use the clearTable() method');
     }
 }
 /**
  * Delete all objects
  *
  * This creates a single delete query using the complete keys of 
  * each of the dbobjects that has been registered
  */
 function delete()
 {
     if (count($this->dbobjects) && is_array($this->dbobjects)) {
         $clause = new Clause();
         $class_name = $this->class_name;
         $obj = new $class_name();
         DbObject::cascadeDelete($this->dbobjects);
         foreach ($this->dbobjects as $dbobj) {
             /**$sub_clause = new Clause();
             
                                 foreach($dbobj->primaryKeys() as $field)
                                 {
                                     $sub_clause->addTableCondition($obj->tableName(),$field->name(),$field->value());
                                 }*/
             if ($dbobj->db_clause) {
                 $clause->addSubClause($dbobj->db_clause, Clause::OR_REL, Clause::LAST);
             } else {
                 $clause->addSubClause($dbobj->uniqueClause(), Clause::OR_REL, Clause::LAST);
             }
         }
         $query = new DeleteQuery($obj->tableName());
         $query->setClause($clause);
         Session::unRegister($this->class_name . '_rel_deleteregister');
         $query->doQuery();
     }
 }