You are here

function RelationQuery::execute in Relation 7

Executes the query.

After executing the query, $this->orderedResults will contain a list of the same stub entities in the order returned by the query. This is only relevant if there are multiple entity types in the returned value and a field ordering was requested. In every other case, the returned value contains everything necessary for processing.

Return value

Either a number if count() was called or an array of associative arrays of stub entities. The outer array keys are entity types, and the inner array keys are the relevant ID. (In most cases this will be the entity ID. The only exception is when age=FIELD_LOAD_REVISION is used and field conditions or sorts are present -- in this case, the key will be the revision ID.) The entity type will only exist in the outer array if results were found. The inner array values are always stub entities, as returned by entity_create_stub_entity(). To traverse the returned array:


    foreach ($query->execute() as $entity_type => $entities) {
      foreach ($entities as $entity_id => $entity) {
  

Note if the entity type is known, then the following snippet will load the entities found:

$result = $query
  ->execute();
if (!empty($result[$my_type])) {
  $entities = entity_load($my_type, array_keys($result[$my_type]));
}

Overrides EntityFieldQuery::execute

File

./relation.database.inc, line 50
Database query functions.

Class

RelationQuery
Handler class for entity relations.

Code

function execute() {
  $results = parent::execute();
  if ($this->count) {
    return $results;
  }
  return isset($results['relation']) ? $results['relation'] : array();
}