Project VersionsSearchTable Of ContentsPrevious topicNext topicClass Phalcon\Mvc\Model\Query\Lang This Page |
Class Phalcon\Mvc\Model\Query\Builder¶implements Phalcon\Mvc\Model\Query\BuilderInterface, Phalcon\DI\InjectionAwareInterface Helps to create PHQL queries using an OO interface <?php
$resultset = $this->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 Phalcon\Mvc\Model\Query\Builder setDI (Phalcon\DiInterface $dependencyInjector) Sets the DependencyInjector container public Phalcon\DiInterface getDI () Returns the DependencyInjector container public Phalcon\Mvc\Model\Query\Builder columns (string|array $columns) Sets the columns to be queried <?php
$builder->columns(array('id', 'name'));
public string|array getColumns () Return the columns to be queried public Phalcon\Mvc\Model\Query\Builder from (string|array $models) Sets the models who makes part of the query <?php
$builder->from(array('Robots', 'RobotsParts'));
public Phalcon\Mvc\Model\Query\Builder addFrom (string $model, [string $alias]) Add a model to take part of the query <?php
$builder->addFrom('Robots', 'r');
public string|array getFrom () Return the models who makes part of the query public Phalcon\Mvc\Model\Query\Builder join (string $model, [string $conditions], [string $alias], [string $type]) Adds a join to the query <?php
$builder->join('Robots', 'r.id = RobotsParts.robots_id', 'r');
public Phalcon\Mvc\Model\Query\Builder leftJoin (string $model, [string $conditions], [string $alias]) Adds a LEFT join to the query <?php
$builder->leftJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
public Phalcon\Mvc\Model\Query\Builder rightJoin (string $model, [string $conditions], [string $alias]) Adds a RIGHT join to the query <?php
$builder->rightJoin('Robots', 'r.id = RobotsParts.robots_id', 'r');
public Phalcon\Mvc\Model\Query\Builder where (string $conditions) Sets the query conditions <?php
$builder->where('name = :name: AND id > :id:');
public Phalcon\Mvc\Model\Query\Builder andWhere (string $conditions) Appends a condition to the current conditions using a AND operator <?php
$builder->andWhere('name = :name: AND id > :id:');
public Phalcon\Mvc\Model\Query\Builder orWhere (string $conditions) Appends a condition to the current conditions using a OR operator <?php
$builder->orWhere('name = :name: AND id > :id:');
public string|array getWhere () Return the conditions for the query public Phalcon\Mvc\Model\Query\Builder orderBy (string $orderBy) Sets a ORDER BY condition clause <?php
$builder->orderBy('Robots.name');
$builder->orderBy(array('1', 'Robots.name'));
public string|array getOrderBy () Returns the set ORDER BY clause public Phalcon\Mvc\Model\Query\Builder having (string $having) Sets a HAVING condition clause. You need to escape PHQL reserved words using [ and ] delimiters <?php
$builder->having('SUM(Robots.price) > 0');
public string|array getHaving () Return the current having clause public Phalcon\Mvc\Model\Query\Builder limit (int $limit, [int $offset]) Sets a LIMIT clause, optionally a offset clause <?php
$builder->limit(100);
$builder->limit(100, 20);
public string|array getLimit () Returns the current LIMIT clause public Phalcon\Mvc\Model\Query\Builder offset (int $offset) Sets an OFFSET clause <?php
$builder->offset(30);
public string|array getOffset () Returns the current OFFSET clause public Phalcon\Mvc\Model\Query\Builder groupBy (string $group) Sets a GROUP BY clause <?php
$builder->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 Phalcon\Mvc\Model\Query getQuery () Returns the query built |