Class **Phalcon\\Mvc\\Model\\Query\\Builder** ============================================= *implements* :doc:`Phalcon\\Mvc\\Model\\Query\\BuilderInterface `, :doc:`Phalcon\\DI\\InjectionAwareInterface ` Helps to create PHQL queries using an OO interface .. code-block:: php modelsManager->createBuilder() ->from('Robots') ->join('RobotsParts') ->limit(20) ->orderBy('Robots.name') ->getQuery() ->execute(); Methods --------- public **__construct** ([*array* $params]) Phalcon\\Mvc\\Model\\Query\\Builder constructor public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **setDI** (:doc:`Phalcon\\DiInterface ` $dependencyInjector) Sets the DependencyInjector container public :doc:`Phalcon\\DiInterface ` **getDI** () Returns the DependencyInjector container public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **columns** (*string|array* $columns) Sets the columns to be queried .. code-block:: php columns(array('id', 'name')); public *string|array* **getColumns** () Return the columns to be queried public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **from** (*string|array* $models) Sets the models who makes part of the query .. code-block:: php from(array('Robots', 'RobotsParts')); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **addFrom** (*string* $model, [*string* $alias]) Add a model to take part of the query .. code-block:: php addFrom('Robots', 'r'); public *string|array* **getFrom** () Return the models who makes part of the query public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **join** (*string* $model, [*string* $conditions], [*string* $alias], [*string* $type]) Adds a join to the query .. code-block:: php join('Robots'); $builder->join('Robots', 'r.id = RobotsParts.robots_id'); $builder->join('Robots', 'r.id = RobotsParts.robots_id', 'r'); $builder->join('Robots', 'r.id = RobotsParts.robots_id', 'r', 'LEFT'); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **leftJoin** (*string* $model, [*string* $conditions], [*string* $alias]) Adds a LEFT join to the query .. code-block:: php leftJoin('Robots', 'r.id = RobotsParts.robots_id', 'r'); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **rightJoin** (*string* $model, [*string* $conditions], [*string* $alias]) Adds a RIGHT join to the query .. code-block:: php rightJoin('Robots', 'r.id = RobotsParts.robots_id', 'r'); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **where** (*string* $conditions, [*array* $bindParams], [*array* $bindTypes]) Sets the query conditions .. code-block:: php where('name = :name: AND id > :id:'); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **andWhere** (*string* $conditions, [*array* $bindParams], [*array* $bindTypes]) Appends a condition to the current conditions using a AND operator .. code-block:: php andWhere('name = "Peter"'); $builder->andWhere('name = :name: AND id > :id:', array('name' => 'Peter', 'id' => 100)); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **orWhere** (*string* $conditions, [*array* $bindParams], [*array* $bindTypes]) Appends a condition to the current conditions using a OR operator .. code-block:: php orWhere('name = "Peter"'); $builder->orWhere('name = :name: AND id > :id:', array('name' => 'Peter', 'id' => 100)); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **betweenWhere** (*string* $expr, *mixed* $minimum, *mixed* $maximum) Appends a BETWEEN condition to the current conditions .. code-block:: php betweenWhere('price', 100.25, 200.50); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **inWhere** (*string* $expr, *array* $values) Appends an IN condition to the current conditions .. code-block:: php inWhere('id', [1, 2, 3]); public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **notInWhere** (*string* $expr, *array* $values) Appends a NOT IN condition to the current conditions .. code-block:: php notInWhere('id', [1, 2, 3]); public *string|array* **getWhere** () Return the conditions for the query public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **orderBy** (*string* $orderBy) Sets a ORDER BY condition clause .. code-block:: php orderBy('Robots.name'); $builder->orderBy(array('1', 'Robots.name')); public *string|array* **getOrderBy** () Returns the set ORDER BY clause public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **having** (*string* $having) Sets a HAVING condition clause. You need to escape PHQL reserved words using [ and ] delimiters .. code-block:: php having('SUM(Robots.price) > 0'); public *string|array* **getHaving** () Return the current having clause public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **limit** (*int* $limit, [*int* $offset]) Sets a LIMIT clause, optionally a offset clause .. code-block:: php limit(100); $builder->limit(100, 20); public *string|array* **getLimit** () Returns the current LIMIT clause public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **offset** (*int* $offset) Sets an OFFSET clause .. code-block:: php offset(30); public *string|array* **getOffset** () Returns the current OFFSET clause public :doc:`Phalcon\\Mvc\\Model\\Query\\Builder ` **groupBy** (*string* $group) Sets a GROUP BY clause .. code-block:: php groupBy(array('Robots.name')); public *string* **getGroupBy** () Returns the GROUP BY clause public *string* **getPhql** () Returns a PHQL statement built based on the builder parameters public :doc:`Phalcon\\Mvc\\Model\\Query ` **getQuery** () Returns the query built