EntityFieldQuery: Load all revisions I have a self-defined entity with revisions called command. The instance with id=1 has 3 revisions. Now I want to load all these revisions. Tried this:

$query = new EntityFieldQuery();

$query
  -&gt;entityCondition('entity_type', 'command')
  -&gt;propertyCondition('id', 1)
  -&gt;age(FIELD_LOAD_REVISION)
  ;
$result = $query-&gt;execute();


but it gives me still only one revision, the current one. There's no difference to calling it without -&gt;age(FIELD_LOAD_REVISION).

What am I doing wrong?
Solution: Use a regular query instead of a EntityFieldQuery to load all entity revisions.

Explanation:

In the age function on entity.inc there's this comment:


  Blockquote
     * Note that this only affects field conditions. Property conditions always
     * apply to the current revision.


So as long as you provide a property condition, you will get only the last revision id. If you query with fieldCondition, you will get the revisions, as the age method is actually querying the field revision table and not the node revision one (field_sql_storage.module):

  else {
    $tablename_function = '_field_sql_storage_revision_tablename';
    $id_key = 'revision_id';
  }


Otherwise, the entity table is queried so it will always return the entities and not the revisions.

You could do a addTag and modify the query object there but at this point the modifications will be so big that it's actually better to do a regular query instead. 

Example using generic info for the entity and entity api entity_revision_load.

  $entity_type = 'command';
  $value = 1;
  $entity_info = entity_get_info($entity_type);

  $query = db_select($entity_info['revision table'], 'revision');
  $query-&gt;fields('revision', array($entity_info['entity keys']['id'], $entity_info['entity keys']['revision']))
    -&gt;condition('revision.' . $entity_info['entity keys']['id'], $value);
  $revisions = $query
    -&gt;execute()
    -&gt;fetchAllAssoc($entity_info['entity keys']['revision']);

  $entities = array();
  foreach ($revisions as $key =&gt; $revision) {
    $entities[] = entity_revision_load($entity_type, $key);
  }