I'm using EntityFieldQuery and want to change the query target to something other than 'default' (because I'm using DB replication with the help of autoslave module).

It's easy to do that when using db_select or db_query by setting 'target' key on third $options parameter.

EntityFieldQuery class doesn't have any method for that and I tried to use hook_query_alter but no luck there too.

1 Answer 1


This is currently not possible (Drupal 7.43). EntityFieldQuery doesn't have any options for using a slave/replica database, nor does the module that actually executes the query, which is field_sql_storage.module in field_sql_storage_field_storage_query().

Ultimately that function calls db_select():

$select_query = db_select($tablename, $table_alias);

But it doesn't pass the 3rd parameter which is where the slave database would be targeted, so it will always use the master. It's also not possible to alter the query to add new options, as the Query->queryOptions property is protected.

I filed an issue against Drupal core, if it gets fixed the solution will be posted there: https://www.drupal.org/node/2714021


Your Answer

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

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