lithium\data\source\Database::delete()

public method

Deletes a record in the database based on the given Query.

Parameters

  • object $query

    An SQL string, or lithium\data\model\Query object instance.

  • array $options

    If $query is a string, $options is the array of quoted/escaped parameter values to be inserted into the query.

Returns

boolean

Returns true on successful query execution (not necessarily if records are deleted), otherwise false.

Filter

This method can be filtered.

Source

	public function delete($query, array $options = []) {
		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$query = $params['query'];
			$isObject = is_object($query);

			if ($isObject) {
				$sql = $this->renderCommand('delete', $query->export($this), $query);
			} else {
				$sql = Text::insert($query, $this->value($params['options']));
			}
			$result = (boolean) $this->_execute($sql);

			if ($result && $isObject && $query->entity()) {
				$query->entity()->sync(null, [], ['dematerialize' => true]);
			}
			return $result;
		});
	}