Cake\Database\Query::modifier PHP Метод

modifier() публичный Метод

By default this function will append any passed argument to the list of modifiers to be applied, unless the second argument is set to true. ### Example: Ignore cache query in MySQL $query->select(['name', 'city'])->from('products')->modifier('SQL_NO_CACHE'); It will produce the SQL: SELECT SQL_NO_CACHE name, city FROM products Or with multiple modifiers $query->select(['name', 'city'])->from('products')->modifier(['HIGH_PRIORITY', 'SQL_NO_CACHE']); It will produce the SQL: SELECT HIGH_PRIORITY SQL_NO_CACHE name, city FROM products
public modifier ( array | Cake\Database\ExpressionInterface | string $modifiers, boolean $overwrite = false )
$modifiers array | Cake\Database\ExpressionInterface | string modifiers to be applied to the query
$overwrite boolean whether to reset order with field list or not
    public function modifier($modifiers, $overwrite = false)
    {
        $this->_dirty();
        if ($overwrite) {
            $this->_parts['modifier'] = [];
        }
        $this->_parts['modifier'] = array_merge($this->_parts['modifier'], (array) $modifiers);
        return $this;
    }

Usage Example

 /**
  * Modify the limit/offset to TSQL
  *
  * @param \Cake\Database\Query $query The query to translate
  * @return \Cake\Database\Query The modified query
  */
 protected function _selectQueryTranslator($query)
 {
     $skip = false;
     $limit = $query->clause('limit');
     $offset = $query->clause('offset');
     if (isset($query->clause('select')['count'])) {
         //TODO instanceof \Cake\Database\Expression\FunctionExpression)
         $skip = true;
     }
     if ($limit && !$offset && !$skip) {
         $query->modifier(['_auto_top_' => sprintf('FIRST %d', $limit)]);
     }
     if ($limit && $offset && !$skip) {
         $query->modifier(['_auto_top_' => sprintf('FIRST %d SKIP %d', $limit, $offset)]);
     }
     if ($skip) {
         $query->modifier(['_auto_top_' => '']);
     }
     return $this->_transformDistinct($query);
 }
All Usage Examples Of Cake\Database\Query::modifier