EntityFieldQuery with Workflow I need to filter an EntityFieldQuery with a given workflow state, let's say workflow it is state 21 (sid = 21). Below, the query I am using

$query_formularios_completos = new EntityFieldQuery();
  $query_formularios_completos
    -&gt;entityCondition('entity_type', 'node')
    -&gt;propertyCondition('type', array(
        'evento_agencia',
        'evento_energia'
      )
    )
    -&gt;propertyCondition('workflow', 21)
    -&gt;fieldCondition('field_e_expositor', 'target_id', $node_expositor_nid);
  $result_formularios_completos = $query_formularios_completos-&gt;execute();


When using DEVEL to inspect my node, I can see there is a property -&gt;workflow, side by side with ordinary properties like -&gt;title or -&gt;created. Although I can see it there and I expected to filter only items with workflow state 21, I get a horrid database error when trying to execute the code above. Here is more or less the message I get:


  Column not found: 1054 Column 'node.workflow' unknown in 'where
  clause'


Any ideas on how I should filter an entity query using a workflow state as filter? Maybe what I am trying to do isn'tpossible and I have to actually run a query using db_query and applying the appropriate joins.
As described in EntityFieldQuery::propertyCondition(), you can use that method for every database field defined in the hook_schema() implementation for the base database table used from the entity.


  $column: A column defined in the hook_schema() of the base table of the entity.


The code that effectively handle that is in EntityFieldQuery::propertyQuery() which contains the following code.

  $entity_type = $this-&gt;entityConditions['entity_type']['value'];
  $entity_info = entity_get_info($entity_type);
  if (empty($entity_info['base table'])) {
    throw new EntityFieldQueryException(t('Entity %entity has no base table.', array('%entity' =&gt; $entity_type)));
  }
  $base_table = $entity_info['base table'];
  $base_table_schema = drupal_get_schema($base_table);
  $select_query = db_select($base_table);
  $select_query-&gt;addExpression(':entity_type', 'entity_type', array(':entity_type' =&gt; $entity_type));
  // Process the property conditions.
  foreach ($this-&gt;propertyConditions as $property_condition) {
    $this-&gt;addCondition($select_query, $base_table . '.' . $property_condition['column'], $property_condition);
  }


You could implement hook_entity_query_alter(), which is invoked before EntityFieldQuery::propertyQuery() is called, and which (by default) it's the EntityFieldQuery::executeCallback callback, the same callback hook_entity_query_alter() is suggested to change. Using your own callback, you could make a join with the tables the Workflow module is using.