title: Rails 4 One query for select users from workspace with specific role (has_many through)
body: <p>I have following models:</p>
  
  <pre><code>class Workspace &lt; ActiveRecord::Base
  ...
    has_many :workspaces_memberships, :dependent =&gt; :destroy
    has_many :users, :through =&gt; :workspaces_memberships
    has_many :roles, :through =&gt; :workspaces_memberships
  ...
  end
  
  class WorkspacesMembership &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :workspace, touch: true
    belongs_to :role
  ...
  end
  </code></pre>
  
  <p>I want to select <code>all users</code> from <code>workspace</code>, who have role <code>admin</code> (<code>role_id 1</code>, but it would be brilliant to search it by name in <code>Role</code> model) in one query (in <code>WorkspacesMembership</code> model I have <code>user_id</code>, <code>workspace_id</code>, <code>role_id</code>). </p>
  
  <p>Any suggestions?</p>