prepare() public method

public prepare ( $builder )
Exemplo n.º 1
0
 public function prepare($builder)
 {
     if ($this->type !== null) {
         $this->andWhere(['type' => $this->type]);
     }
     return parent::prepare($builder);
 }
Exemplo n.º 2
0
 public function prepare($builder)
 {
     if ($this->type !== null) {
         $this->andWhere(['competition_type' => $this->type]);
         Yii::trace($this->type, 'CompetitionQuery::prepare');
     }
     return parent::prepare($builder);
 }
Exemplo n.º 3
0
 public function prepare($builder)
 {
     // override private `buildJoinWith()`
     if (!empty($this->joinWith)) {
         $this->buildJoinWith();
         $this->joinWith = null;
         // clean it up to avoid issue https://github.com/yiisoft/yii2/issues/2687
     }
     if (empty($this->from)) {
         $this->from = [$this->finder->tableName()];
     }
     return parent::prepare($builder);
 }
Exemplo n.º 4
0
 /**
  * @param \yii\db\QueryBuilder $builder
  * @return \yii\db\Query
  * @throws \yii\base\InvalidConfigException
  */
 public function prepare($builder)
 {
     /** @var ActiveRecord $modelClass */
     $modelClass = $this->modelClass;
     $schema = $modelClass::getTableSchema();
     if (empty($this->select)) {
         $this->select('*');
         foreach ($schema->columns as $column) {
             if (ActiveRecord::isSpatial($column)) {
                 $field = $column->name;
                 $this->addSelect(["AsText({$field}) AS {$field}"]);
             }
         }
     } else {
         foreach ($this->select as $column => $field) {
             $column = $schema->getColumn(is_numeric($column) ? $field : $column);
             if (ActiveRecord::isSpatial($column)) {
                 $this->addSelect(["AsText({$field}) AS {$field}"]);
             }
         }
     }
     return parent::prepare($builder);
 }
Exemplo n.º 5
0
 public function prepare($builder)
 {
     if (!$this->_skipPrep) {
         // skip in case of queryScalar; it's not needed, and we get an SQL error (duplicate column names)
         if (empty($this->select)) {
             $this->select('*');
             $this->allColumns();
         } else {
             /** @var ActiveRecord $modelClass */
             $modelClass = $this->modelClass;
             $schema = $modelClass::getTableSchema();
             foreach ($this->select as $field) {
                 if ($field == '*') {
                     $this->allColumns();
                 } else {
                     $column = $schema->getColumn($field);
                     if (ActiveRecord::isSpatial($column)) {
                         $this->addSelect(["AsText({$field}) AS {$field}"]);
                     }
                 }
             }
         }
     }
     return parent::prepare($builder);
 }
Exemplo n.º 6
0
 /**
  * @param ActiveQuery $query1
  * @param ActiveQuery $query2
  * @param string $message
  */
 public function assertSqlQuery($query1, $query2, $message = '')
 {
     $this->assertEquals($query1->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql, $query2->prepare(Yii::$app->db->queryBuilder)->createCommand()->rawSql, $message);
 }
 public function prepare($builder)
 {
     $this->andWhere(['is_layout' => (bool) $this->isLayout]);
     return parent::prepare($builder);
 }
 /**
  * Maria-specific preparation for building a query that includes a dynamic column.
  *
  * @param \yii\db\QueryBuilder $builder
  *
  * @return \yii\db\Query
  * @throws \yii\base\Exception
  * @throws \yii\base\InvalidConfigException
  */
 public function prepare($builder)
 {
     /** @var DynamicActiveRecord $modelClass */
     $modelClass = $this->modelClass;
     $this->_dynamicColumn = $modelClass::dynamicColumn();
     if (empty($this->_dynamicColumn)) {
         /** @var string $modelClass */
         throw new \yii\base\InvalidConfigException($modelClass . '::dynamicColumn() must return an attribute name');
     }
     if (empty($this->select)) {
         $this->select[] = '*';
     }
     if (is_array($this->select) && in_array('*', $this->select)) {
         $db = $modelClass::getDb();
         $this->select[$this->_dynamicColumn] = 'COLUMN_JSON(' . $db->quoteColumnName($this->_dynamicColumn) . ')';
     }
     return parent::prepare($builder);
 }