Get all users with specific roles using EntityFieldQuery I thought this was an easy task, yet there does not seem to be a Drupal-method for this. I came as far as knowing I have to use EntityFieldQuery for this - because the API said conditions for user_load_multiple() are deprecated. 

So I tried this:

  $query = new EntityFieldQuery;
  $query
    -&gt;entityCondition('entity_type', 'user')
    -&gt;propertyCondition('rid',array(1,2,3);

  $result = $query-&gt;execute();


Yet I got this:


  PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column
  'users.rid' in 'where clause': SELECT users.uid AS entity_id,
  :entity_type AS entity_type, NULL AS revision_id, :bundle AS bundle
  FROM {users} users WHERE (users.rid = :db_condition_placeholder_0) ;
  Array ( [:db_condition_placeholder_0] => 3 [:entity_type] => user
  [:bundle] => user ) in EntityFieldQuery->execute()


So my first thought was, that I'd have to join with users_roles-Table and so on, but that will lead to duplicates. 

Does anyone have an idea how to do it?
To be honest, I have no idea on how to achieve this. Good examples of how to use the EntityFieldQuery are hard to find. Since noone has answered this question yet and I'm also interested in the solution I'll try to help you out. Described below is my best guess.

A thing to keep in mind: roles are stored in a different table than users. They are added using UserController::attachLoad.

There seem to be three different conditions that you can use with an EntityFieldQuery:


entityCondition (Entity specific conditions:'entity_type',
'bundle', 'revision_id' or 'entity_id')
fieldCondition (Conditions on fields maintained by the Field
API)
propertyCondition (Conditions on entity properties)


The most logical option (if there is one) would be to use a propertyCondition, but as roles are added to the user in UserController::attachLoad I don't think the EntityFieldQuery has access to it. I think the EntityFieldQuery just uses the schema defined in hook_schema().

This leads me to believe that what you're trying to achieve is impossible. A workaround would be to get all the uids with a normal query:

I don't have access to Drupal right now, so the code below might be off. I'm sure somebody will edit the mistakes.

// Use $query for readability
$query = 'SELECT DISTINCT(ur.uid) 
  FROM {users_roles} AS ur
  WHERE ur.rid IN (:rids)';
$result = db_query($query, array(':rids' =&gt; array(1,2,3)));

$uids = $result-&gt;fetchCol();

$users = user_load_multiple($uids);


If it is possible to achieve what you want with EntityFieldQuery, I'll be enlightened.