lithium\data\model\Query::__construct()

public method

Constructor, which initializes the default values this object supports. Even though only a specific list of configuration parameters is available by default, the Query object uses the __call() method to implement automatic getters and setters for any arbitrary piece of data.

This means that any information may be passed into the constructor may be used by the backend data source executing the query (or ignored, if support is not implemented). This is useful if, for example, you wish to extend a core data source and implement custom functionality.

Parameters

  • array $config

    Available configuration options are:

    • 'type' string: The type of the query (read, create, update, delete).
    • 'mode' string: JOIN mode for a join query.
    • 'entity' object: The base entity to query on. If set 'model' is optionnal.
    • 'model' string: The base model to query on.
    • 'source' string: The name of the table/collection. Unnecessary if model is set.
    • 'alias' string: Alias for the source. Unnecessary if model is set.
    • 'schema' object: A schema model. Unnecessary if model is set.
    • 'fields' array: The fields to retreive.
    • 'conditions' array: The conditions of the queries
    • 'having' array: The having conditions of the queries
    • 'group' string: The group by parameter.
    • 'order' string: The order by parameter.
    • 'limit' string: The limit parameter.
    • 'offset' string: The offset of the limit options.
    • 'page' string: Convenience parameter for setting the offset: offset = page * limit.
    • 'with' array: Contain dependencies. Works only if model is set.
    • 'joins' array: Contain manual join dependencies.
    • 'data' array: Datas for update queries.
    • 'whitelist' array: Allowed fields for updating queries.
    • 'calculate' string: Alias name of the count.
    • 'comment' string: Comment for the query.
    • 'map' object: Unnecessary if model is set.
    • 'relationships' array: Unnecessary if model is set.

Returns

void

Source

	public function __construct(array $config = []) {
		$defaults = [
			'type' => 'read',
			'mode' => null,
			'model' => null,
			'entity' => null,
			'source' => null,
			'alias' => null,
			'fields' => [],
			'conditions' => [],
			'having' => [],
			'group' => null,
			'order' => null,
			'limit' => null,
			'offset' => null,
			'page' => null,
			'with' => [],
			'joins' => [],
			'data' => [],
			'whitelist' => [],
			'calculate' => null,
			'schema' => null,
			'comment' => null,
			'map' => [],
			'relationships' => []
		];
		$this->_autoConfig($config + $defaults, $this->_autoConfig);
		$this->_autoInit($config);
	}