public function EntityFieldQuery::entityCondition

You are here

7 entity.inc public EntityFieldQuery::entityCondition($name, $value, $operator = NULL)

Adds a condition on entity-generic metadata.

If the overall query contains only entity conditions or ordering, or if there are property conditions, then specifying the entity type is mandatory. If there are field conditions or ordering but no property conditions or ordering, then specifying an entity type is optional. While the field storage engine might support field conditions on more than one entity type, there is no way to query across multiple entity base tables by default. To specify the entity type, pass in 'entity_type' for $name, the type as a string for $value, and no $operator (it's disregarded).

'bundle', 'revision_id' and 'entity_id' have no such restrictions.

Note: The "comment" entity type does not support bundle conditions.

Parameters

$name: 'entity_type', 'bundle', 'revision_id' or 'entity_id'.

$value: The value for $name. In most cases, this is a scalar. For more complex options, it is an array. The meaning of each element in the array is dependent on $operator.

$operator: Possible values:

  • '=', '<>', '>', '>=', '<', '<=', 'STARTS_WITH', 'CONTAINS': These operators expect $value to be a literal of the same type as the column.
  • 'IN', 'NOT IN': These operators expect $value to be an array of literals of the same type as the column.
  • 'BETWEEN': This operator expects $value to be an array of two literals of the same type as the column.

The operator can be omitted, and will default to 'IN' if the value is an array, or to '=' otherwise.

Return value

EntityFieldQuery The called object.

File

includes/entity.inc, line 617

Class

EntityFieldQuery
Retrieves entities matching a given set of conditions.

Code

public function entityCondition($name, $value, $operator = NULL) {
  // The '!=' operator is deprecated in favour of the '<>' operator since the
  // latter is ANSI SQL compatible.
  if ($operator == '!=') {
    $operator = '<>';
  }
  $this->entityConditions[$name] = array(
    'value' => $value,
    'operator' => $operator,
  );
  return $this;
}

Comments

Can we use `OR` with entityCondition (or any other conditions: fieldCondition and propertyCondition)?

now that $conditions is deprecated in
file_load_multiple($fids = array(), $conditions = array())

you can use the following:

$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'file')
->propertyCondition('uri', $fileURI)
->execute();

to load the actual file you can use something like this

if($result) {
$row = array_pop(array_pop($result));
var_dump(file_load($row->fid));
}