Build an EntityFieldQuery that selects referenced entities I am looking for the ID of the entity of type A and I know the ID of entity B that references A.

I found a few nice sources about EntityFieldQuery. I was amazed that i was getting results from .NET in google :) (is it a sign of Drupal's maturity ? :). But didnt manage to find this. Please help ...

Some of the sources :


How to on d.o
Discussion about building an example
An example module on github


This is what it looks like with entity loads - you will understand i need that query :) The wrapper is there for practice mainly. Note that it loads the target entity - quite a lot of queries.

  $b = entity_load('B', array($id));
  $bm = entity_metadata_wrapper('B', $sl[$id]);

  $tsl = $slm-&gt;field_sl_tpref-&gt;value();
  echo $tsl-&gt;id;
You can use target_id instead of value to retrieve entities based on the ID of referenced entities:

$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', &lt;type-of-the-entity&gt;);
$query-&gt;fieldCondition('&lt;name-of-the-field-referring-the-other-entity&gt;', 'target_id', &lt;id-of-the-referenced-entity&gt;, '=');
$results = $query-&gt;execute();