Using entity query build to select entities applying conditions on all revisions Background

Best practice deems that you should use EntityFieldQuery (d7) for making queries that somehow involves fields on entites.

An example of such a query could look like this.

$query = new EntityFieldQuery();
$result = $query-&gt;entityCondition('entity_type', 'node')
  -&gt;fieldCondition('field_foo', 'value', REQUEST_TIME, '&gt;')
  -&gt;execute();


In the above example, we are looking for nodes which has a timestamp value set in the future, it works just fine and all is good.

Question

Is it possible using these APIs (which handles that fields potentially could be stored anywhere), and apply the condition on all revisions, instead of only the active revision?

When using SQL, you could make a custom query on the field_revision_FIELDNAME table, but doing this would require you to make some database assumptions and break best practice.
Yes. EntityFieldQuery has a property EntityFieldQuery::$age that is a flag for the age of the returned entity revision. It can be set to:


FIELD_LOAD_CURRENT (default): for only the current revision (e.g. $query-&gt;age = FIELD_LOAD_CURRENT;)
FIELD_LOAD_REVISION - for all revisions (e.g. $query-&gt;age = FIELD_LOAD_REVISION;)


Support for this flag ultimately depends on the EFQ's queryCallback function. In the default field_sql_storage_field_storage_query() function, it is recognized and queries the appropriate revision tables accordingly.