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();
    ->entityCondition('entity_type', 'node')
    ->propertyCondition('type', array(
    ->propertyCondition('workflow', 21)
    ->fieldCondition('field_e_expositor', 'target_id', $node_expositor_nid);
  $result_formularios_completos = $query_formularios_completos->execute();

When using DEVEL to inspect my node, I can see there is a property ->workflow, side by side with ordinary properties like ->title or ->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.

  • 3
    workflow isn't a property (in the sense of an 'entity property') it's a value that the workflow module tacks on to a node object in an implementation of hook_node_load(). You either need to run a manual query like you say, or use addTag() to add a tag to the query, then use hook_query_TAG_alter() to alter the query when it's been converted down to a standard SelectQuery. At that point joining the workflow will be easy
    – Clive
    Aug 15, 2013 at 10:46
  • Thanks, Clive, I did it with db_query. In the end, doing it this was simpler... Thks a lot, upvoted your comment... Aug 15, 2013 at 11:55
  • 1
    Random comment ... I speak/write English and Spanish; and I'm working on Korean now. I've seen Ada code in English/French and lots of stuff in English/Spanish ... it's a poor implementation choice as it makes the code harder to maintain in the future (once you're personally off the project). Code should always be written in 1 (spoken) language.
    – tenken
    Aug 15, 2013 at 16:23
  • @MarcosBuarque - Can you share your db_query example please? Jan 30, 2017 at 11:52

1 Answer 1


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->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' => $entity_type)));
  $base_table = $entity_info['base table'];
  $base_table_schema = drupal_get_schema($base_table);
  $select_query = db_select($base_table);
  $select_query->addExpression(':entity_type', 'entity_type', array(':entity_type' => $entity_type));
  // Process the property conditions.
  foreach ($this->propertyConditions as $property_condition) {
    $this->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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.