Flag module not joining flagging with EntityFieldQuery? I'm using EntityFieldQuery to pull nodes based on a flag created with the Flag module (3.2):

  $query = new EntityFieldQuery();
  $query-&gt;entityCondition('entity_type', 'node')
    -&gt;entityCondition('bundle', 'article')
    -&gt;propertyCondition('status', 1)
    -&gt;range(0, 25)
    -&gt;addTag('flagging_flag_names')
    -&gt;addMetaData('flag_name_value', 'my_flag_name');


I'm not seeing the flagging table being joined to the query (from the error being thrown):

Unknown column 'flagging.fid' in 'on clause': 
SELECT node.nid AS entity_id, node.vid AS revision_id, node.type AS bundle, 'node' AS entity_type FROM node node INNER JOIN flag f ON flagging.fid = f.fid WHERE (node.status = 1) AND (node.type = 'article') AND (f.name = 'my_flag_name') LIMIT 25 OFFSET 0


Below is the flag_query_flagging_flag_names_alter from the flag module file:

function flag_query_flagging_flag_names_alter(QueryAlterableInterface $query) {
  // Get value and operator for bundle condition from meta data.
  $value = $query-&gt;getMetaData('flag_name_value');
  $operator = $query-&gt;getMetaData('flag_name_operator');
  // Join [flag] and [flagging] tables by [fid] and
  // apply bundle condition on [flag].[name] field.
  $query-&gt;join('flag', 'f', 'flagging.fid = f.fid');
  $query-&gt;condition('f.name', $value, $operator);
}


What am I missing in the query build to join the flagging table?
The flagging table is not available when querying for nodes using an EntityFieldQuery, that's why the flagging.fid column is missing in this query.

In order to get hold of flaged items, the flagging-entities need to be queried instead:

$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'flagging')
  -&gt;entityCondition('bundle', 'name_of_some_flag');


Then use entity_load('flagging', ...) and obtain the nid from the entity_id-property of the flagging entities.

However keep in mind that it is impossible to sort / filter on properties of the target object (nodes in this case) because EntityFieldQuery does not support JOINs in Drupal 7.

I suggest to build a view instead of trying to battle the EFQ in this particular case.