FOF30\Model\DataModel::trash PHP Method

trash() public method

Trashes a record, either the currently loaded one or the one specified in $id. If an $id is specified that record is loaded before trying to trash it. Unlike a hard delete, trashing is a "soft delete", only setting the enabled field to -2.
public trash ( mixed $id = null )
$id mixed Primary key (id field) value
    public function trash($id = null)
    {
        if (!empty($id)) {
            $this->findOrFail($id);
        }
        $id = $this->getId();
        if (!$id) {
            throw new RecordNotLoaded("Can't trash a not loaded DataModel");
        }
        if (!$this->hasField('enabled')) {
            throw new SpecialColumnMissing("DataModel::trash method needs an 'enabled' field");
        }
        $this->triggerEvent('onBeforeTrash', array(&$id));
        $enabled = $this->getFieldAlias('enabled');
        $this->{$enabled} = -2;
        $this->save();
        $this->triggerEvent('onAfterTrash', array(&$id));
        return $this;
    }