/** * Removes a bean from the database. * This function will remove the specified RedBean_OODBBean * Bean Object from the database. * * @param RedBean_OODBBean|RedBean_SimpleModel $bean bean you want to remove from database * * @return void * * @throws RedBean_Exception_Security */ public function trash($bean) { if ($bean instanceof RedBean_SimpleModel) { $bean = $bean->unbox(); } if (!$bean instanceof RedBean_OODBBean) { throw new RedBean_Exception_Security('OODB Store requires a bean, got: ' . gettype($bean)); } $this->signal('delete', $bean); foreach ($bean as $property => $value) { if ($value instanceof RedBean_OODBBean) { $bean->removeProperty($property); } if (is_array($value)) { if (strpos($property, 'own') === 0) { $bean->removeProperty($property); } elseif (strpos($property, 'shared') === 0) { $bean->removeProperty($property); } } } if (!$this->isFrozen) { $this->check($bean); } try { $this->writer->deleteRecord($bean->getMeta('type'), array('id' => array($bean->id)), NULL); } catch (RedBean_Exception_SQL $exception) { $this->handleException($exception); } $bean->id = 0; $this->signal('after_delete', $bean); }
/** * Removes a bean from the database. * This function will remove the specified RedBean_OODBBean * Bean Object from the database. * @throws RedBean_Exception_Security $exception * @param RedBean_OODBBean $bean */ public function trash(RedBean_OODBBean $bean) { $idfield = $this->writer->getIDField($bean->getMeta("type")); $this->signal("delete", $bean); $this->check($bean); try { $this->writer->deleteRecord($bean->getMeta("type"), $bean->{$idfield}); } catch (RedBean_Exception_SQL $e) { if ($e->getSQLState() != "42S02" && $e->getSQLState() != "42S22") { throw $e; } } }
/** * Removes a bean from the database. * This function will remove the specified RedBean_OODBBean * Bean Object from the database. * @throws RedBean_Exception_Security $exception * @param RedBean_OODBBean $bean */ public function trash(RedBean_OODBBean $bean) { $idfield = $this->writer->getIDField($bean->getMeta("type")); $this->signal("delete", $bean); $this->check($bean); try { $this->writer->deleteRecord($bean->getMeta("type"), $bean->{$idfield}); } catch (RedBean_Exception_SQL $e) { if (!$this->writer->sqlStateIn($e->getSQLState(), array(RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_COLUMN, RedBean_QueryWriter::C_SQLSTATE_NO_SUCH_TABLE))) { throw $e; } } }