/** * Removes a bean from the database. * This function will remove the specified OODBBean * Bean Object from the database. * * @param OODBBean|SimpleModel $bean bean you want to remove from database * * @return void * * @throws Security */ public function trash($bean) { if ($bean instanceof SimpleModel) { $bean = $bean->unbox(); } if (!$bean instanceof OODBBean) { throw new RedException('OODB Store requires a bean, got: ' . gettype($bean)); } $this->signal('delete', $bean); foreach ($bean as $property => $value) { if ($value instanceof OODBBean) { unset($bean->{$property}); } if (is_array($value)) { if (strpos($property, 'own') === 0) { unset($bean->{$property}); } elseif (strpos($property, 'shared') === 0) { unset($bean->{$property}); } } } if (!$this->isFrozen) { $this->check($bean); } try { $this->writer->deleteRecord($bean->getMeta('type'), array('id' => array($bean->id)), NULL); } catch (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 OODBBean * Bean Object from the database. * * @param OODBBean|SimpleModel $bean bean you want to remove from database * * @return void * * @throws SQLException */ public function trash($bean) { $this->oodb->signal('delete', $bean); foreach ($bean as $property => $value) { if ($value instanceof OODBBean) { unset($bean->{$property}); } if (is_array($value)) { if (strpos($property, 'own') === 0) { unset($bean->{$property}); } elseif (strpos($property, 'shared') === 0) { unset($bean->{$property}); } } } try { $this->writer->deleteRecord($bean->getMeta('type'), array('id' => array($bean->id)), NULL); } catch (SQLException $exception) { $this->handleException($exception); } $bean->id = 0; $this->oodb->signal('after_delete', $bean); }