RedBeanPHP\Repository::trash PHP Method

trash() public method

This function will remove the specified OODBBean Bean Object from the database.
public trash ( redbeanphp\OODBBean | redbeanphp\SimpleModel $bean ) : void
$bean redbeanphp\OODBBean | redbeanphp\SimpleModel bean you want to remove from database
return void
    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);
    }

Usage Example

示例#1
0
 /**
  * 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
  */
 public function trash($bean)
 {
     $bean = $this->unboxIfNeeded($bean);
     return $this->repository->trash($bean);
 }