function Sql::addHavingExpression

Same name in other branches
  1. 9 core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::addHavingExpression()
  2. 8.9.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::addHavingExpression()
  3. 11.x core/modules/views/src/Plugin/views/query/Sql.php \Drupal\views\Plugin\views\query\Sql::addHavingExpression()

Add a complex HAVING clause to the query.

The caller is responsible for ensuring that all fields are fully qualified (TABLE.FIELD) and that the table and an appropriate GROUP BY already exist in the query. Internally the dbtng method "having" is used.

Parameters

$group: The HAVING group to add these to; groups are used to create AND/OR sections. Groups cannot be nested. Use 0 as the default group. If the group does not yet exist it will be created as an AND group.

$snippet: The snippet to check. This can be either a column or a complex expression like "COUNT(table.field) > 3"

$args: An associative array of arguments.

See also

QueryConditionInterface::having()

File

core/modules/views/src/Plugin/views/query/Sql.php, line 1011

Class

Sql
Views query plugin for an SQL query.

Namespace

Drupal\views\Plugin\views\query

Code

public function addHavingExpression($group, $snippet, $args = []) {
    // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all
    // the default group.
    if (empty($group)) {
        $group = 0;
    }
    // Check for a group.
    if (!isset($this->having[$group])) {
        $this->setWhereGroup('AND', $group, 'having');
    }
    // Add the clause and the args.
    $this->having[$group]['conditions'][] = [
        'field' => $snippet,
        'value' => $args,
        'operator' => 'formula',
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.