/** * Removes a bean from the database. * This function will remove the specified OODBBean * Bean Object from the database. * * This facade method also accepts a type-id combination, * in the latter case this method will attempt to load the specified bean * and THEN trash it. * * @param string|OODBBean|SimpleModel $bean bean you want to remove from database * @param integer $id ID if the bean to trash (optional, type-id variant only) * * @return void */ public static function trash($beanOrType, $id = NULL) { if (is_string($beanOrType)) { return self::trash(self::load($beanOrType, $id)); } return self::$redbean->trash($beanOrType); }
/** * Breaks the association between two beans. This method unassociates two beans. If the * method succeeds the beans will no longer form an association. In the database * this means that the association record will be removed. This method uses the * OODB trash() method to remove the association links, thus giving FUSE models the * opportunity to hook-in additional business logic. If the $fast parameter is * set to boolean TRUE this method will remove the beans without their consent, * bypassing FUSE. This can be used to improve performance. * * @param OODBBean $bean1 first bean in target association * @param OODBBean $bean2 second bean in target association * @param boolean $fast if TRUE, removes the entries by query without FUSE * * @return void */ public function unassociate($beans1, $beans2, $fast = NULL) { $beans1 = !is_array($beans1) ? array($beans1) : $beans1; $beans2 = !is_array($beans2) ? array($beans2) : $beans2; foreach ($beans1 as $bean1) { foreach ($beans2 as $bean2) { try { $this->oodb->store($bean1); $this->oodb->store($bean2); $type1 = $bean1->getMeta('type'); $type2 = $bean2->getMeta('type'); $row = $this->writer->queryRecordLink($type1, $type2, $bean1->id, $bean2->id); $linkType = $this->getTable(array($type1, $type2)); if ($fast) { $this->writer->deleteRecord($linkType, array('id' => $row['id'])); return; } $beans = $this->oodb->convertToBeans($linkType, array($row)); if (count($beans) > 0) { $bean = reset($beans); $this->oodb->trash($bean); } } catch (SQLException $exception) { $this->handleException($exception); } } } }
/** * 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 static function trash($bean) { self::$redbean->trash($bean); }