{"action":"created","issue":{"url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/811","labels_url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/811/labels{/name}","comments_url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/811/comments","events_url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/811/events","html_url":"https://github.com/RESTful-Drupal/restful/issues/811","id":125097688,"number":811,"title":"Question: How to filter users by role","user":{"login":"pferlito","id":650450,"avatar_url":"https://avatars.githubusercontent.com/u/650450?v=3","gravatar_id":"","url":"https://api.github.com/users/pferlito","html_url":"https://github.com/pferlito","followers_url":"https://api.github.com/users/pferlito/followers","following_url":"https://api.github.com/users/pferlito/following{/other_user}","gists_url":"https://api.github.com/users/pferlito/gists{/gist_id}","starred_url":"https://api.github.com/users/pferlito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pferlito/subscriptions","organizations_url":"https://api.github.com/users/pferlito/orgs","repos_url":"https://api.github.com/users/pferlito/repos","events_url":"https://api.github.com/users/pferlito/events{/privacy}","received_events_url":"https://api.github.com/users/pferlito/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-06T02:30:38Z","updated_at":"2016-01-07T05:19:45Z","closed_at":null,"body":"I'm working with 2.x. I subclassed Users__1_0 and exposed 'roles' as a public field, and this works:\r\nhttp://example.com/api/v1.0/myusers\r\nbut this doesn't work:\r\nhttp://example.com/api/v1.0/myusers?filter[roles]=1\r\nIt gives me SQL error. Is this because roles is not a property of the user entity?\r\nI'm trying to filter the users by a role id or role name and I'm not sure how to proceed from here.\r\n\r\nAny guidance would be appreciated."},"comment":{"url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/comments/169553717","html_url":"https://github.com/RESTful-Drupal/restful/issues/811#issuecomment-169553717","issue_url":"https://api.github.com/repos/RESTful-Drupal/restful/issues/811","id":169553717,"user":{"login":"pferlito","id":650450,"avatar_url":"https://avatars.githubusercontent.com/u/650450?v=3","gravatar_id":"","url":"https://api.github.com/users/pferlito","html_url":"https://github.com/pferlito","followers_url":"https://api.github.com/users/pferlito/followers","following_url":"https://api.github.com/users/pferlito/following{/other_user}","gists_url":"https://api.github.com/users/pferlito/gists{/gist_id}","starred_url":"https://api.github.com/users/pferlito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pferlito/subscriptions","organizations_url":"https://api.github.com/users/pferlito/orgs","repos_url":"https://api.github.com/users/pferlito/repos","events_url":"https://api.github.com/users/pferlito/events{/privacy}","received_events_url":"https://api.github.com/users/pferlito/received_events","type":"User","site_admin":false},"created_at":"2016-01-07T05:19:45Z","updated_at":"2016-01-07T05:19:45Z","body":"Thanks @jeff-h the post was helpful in finding a solution. Here is what I did to get it working:\r\n1. Subclassed [DataProviderEntity](https://github.com/RESTful-Drupal/restful/blob/7.x-3.x/src/Plugin/resource/DataProvider/DataProviderEntity.php)\r\n2. Implemented dataProviderClassName() in my resource entity class and pointed it to the class from step 1 as per [this post](https://github.com/RESTful-Drupal/restful/wiki/Assigning-a-different-data-provider)\r\n3. Overrode method queryForListFilter()\r\n4. In queryforListFilter() I added a special query tag and added the requested roles to the query metadata\r\n5. In my .module file I implemented [hook_query_alter()](https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_query_alter/7)\r\n6. In hook_query_alter() I retrieved the roles and used them in a join with the USERS_ROLES table like this:\r\n```<php>\r\n      $query->leftJoin('users_roles', 'ur', 'users.uid = ur.uid');\r\n      $query->condition('ur.rid', $rids, 'IN');\r\n```"}}