Error message

You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).

function EntityFieldQuery::addCondition

Adds a condition to an already built SelectQuery (internal function).

This is a helper for hook_entity_query() and hook_field_storage_query().

Parameters

SelectQuery $select_query: A SelectQuery object.

$sql_field: The name of the field.

$condition: A condition as described in EntityFieldQuery::fieldCondition() and EntityFieldQuery::entityCondition().

$having: HAVING or WHERE. This is necessary because SQL can't handle WHERE conditions on aliased columns.

1 call to EntityFieldQuery::addCondition()
EntityFieldQuery::propertyQuery in includes/entity.inc
Queries entity tables in SQL for property conditions and sorts.

File

includes/entity.inc, line 1420

Class

EntityFieldQuery
Retrieves entities matching a given set of conditions.

Code

public function addCondition(SelectQuery $select_query, $sql_field, $condition, $having = FALSE) {
 $method = $having ? 'havingCondition' : 'condition';
 $like_prefix = '';
 switch ($condition['operator']) {
 case 'CONTAINS':
 $like_prefix = '%';
 case 'STARTS_WITH':
 $select_query->{$method}($sql_field, $like_prefix . db_like ($condition['value']) . '%', 'LIKE');
 break;
 default:
 $select_query->{$method}($sql_field, $condition['value'], $condition['operator']);
 }
}

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