How to use EntityFieldQuery::fieldCondition for entity reference field? Suppose, we have an entity "song", that has an entity reference field, called "authors":



I added a filter for this field as a group of checkboxes:



After the user submits the form with checkboxes group, it must be used inside WHERE condition for the list of songs. So, I added the following code:

//query to get the list of entities
$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'song');

if(!is_null($form_state['input']['field_authors'][LANGUAGE_NONE]))
{
    $query-&gt;fieldCondition('field_authors', /* what to put here? */, 
            $form_state['input']['field_authors'][LANGUAGE_NONE], 'in');
}


I don't understand, what value to put into column parameter. I tried target_id, but it doesn't work. Here is the description of field_data_field_authors table:

DESCRIBE field_data_field_authors;
+-------------------------+------------------+------+-----+---------+-------+
| Field                   | Type             | Null | Key | Default | Extra |
+-------------------------+------------------+------+-----+---------+-------+
| entity_type             | varchar(128)     | NO   | PRI |         |       |
| bundle                  | varchar(128)     | NO   | MUL |         |       |
| deleted                 | tinyint(4)       | NO   | PRI | 0       |       |
| entity_id               | int(10) unsigned | NO   | PRI | NULL    |       |
| revision_id             | int(10) unsigned | YES  | MUL | NULL    |       |
| language                | varchar(32)      | NO   | PRI |         |       |
| delta                   | int(10) unsigned | NO   | PRI | NULL    |       |
| field_authors_target_id | int(10) unsigned | NO   | MUL | NULL    |       |
+-------------------------+------------------+------+-----+---------+-------+
You need to use 'target_id'

Your code should by this:

//query to get the list of entities
$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'song');

if(!is_null($form_state['input']['field_authors'][LANGUAGE_NONE]))
{
    $query-&gt;fieldCondition('field_authors', 'target_id', 
            $form_state['input']['field_authors'][LANGUAGE_NONE], 'in');
}


You can found a good explanation here:

How to use EntityFieldQuery with a simple text field?