RedBeanPHP\Facade::trash PHP Method

trash() public static method

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.
public static trash ( $beanOrType, integer $id = NULL ) : void
$id integer 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);
    }

Usage Example

Example #1
0
 /**
  * Test SQLite table rebuilding.
  *
  * @return void
  */
 public function testRebuilder()
 {
     $toolbox = R::getToolBox();
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->xownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->xownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
     $book = R::dispense('book');
     $page = R::dispense('page');
     $book->xownPage[] = $page;
     $id = R::store($book);
     $book = R::load('book', $id);
     asrt(count($book->xownPage), 1);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
     $book->added = 2;
     R::store($book);
     $book->added = 'added';
     R::store($book);
     R::trash($book);
     asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
 }
All Usage Examples Of RedBeanPHP\Facade::trash