public function trash(EntityInterface $entity, array $options = [])
    {
        $primaryKey = (array)$this->_table->getPrimaryKey();

        foreach ($primaryKey as $field) {
            if (!$entity->has($field)) {
                throw new RuntimeException();
            }
        }

        foreach ($this->_table->associations() as $association) {
            if ($this->_isRecursable($association, $this->_table)) {
                $association->cascadeDelete($entity, ['_primary' => false] + $options);
            }
        }

        $data = [$this->getTrashField(false) => new Time()];
        $entity->set($data, ['guard' => false]);

        if ($this->_table->save($entity, $options)) {
            return true;
        }

        return false;
    }
public function trash(EntityInterface $entity, array $options = [])
    {
        $primaryKey = (array)$this->_table->getPrimaryKey();

        foreach ($primaryKey as $field) {
            if (!$entity->has($field)) {
                throw new RuntimeException();
            }
        }

        foreach ($this->_table->associations() as $association) {
            if ($this->_isRecursable($association, $this->_table)) {
                $association->cascadeDelete($entity, ['_primary' => false] + $options);
            }
        }

        $data = [$this->getTrashField(false) => new Time()];
        $entity->set($data, ['guard' => false]);

        if ($this->_table->save($entity, $options)) {
            return true;
        }

        return false;
    }
public function trash ( EntityInterface $ entity , array $ options = [ ] ) { $ primaryKey = ( array ) $ this -> _table -> getPrimaryKey ( ) ; foreach ( $ primaryKey as $ field ) { if ( ! $ entity -> has ( $ field ) ) { throw new RuntimeException ( ) ; } } foreach ( $ this -> _table -> associations ( ) as $ association ) { if ( $ this -> _isRecursable ( $ association , $ this -> _table ) ) { $ association -> cascadeDelete ( $ entity , [ '_primary' => false ] + $ options ) ; } } $ data = [ $ this -> getTrashField ( false ) => new Time ( ) ] ; $ entity -> set ( $ data , [ 'guard' => false ] ) ; if ( $ this -> _table -> save ( $ entity , $ options ) ) { return true ; } return false ; }
Trash given entity.

@param \Cake\Datasource\EntityInterface $entity EntityInterface.
@param array $options Trash operation options.
@return bool
@throws \RuntimeException if no primary key is set on entity.
Trash given entity .