title: How do I write a scope for some object from a many to many relationship?
body: <p>I need to write a scope that I will pass a user's id through and will collect all the user's list associates with all the companies for that user from the <code>users</code> table.</p>
  
  <p>In User.rb:</p>
  
  <pre><code>has_many :employments
  has_many :companies, :through =&gt; :employments, :dependent =&gt; :destroy
  ...
  </code></pre>
  
  <p>In Employment.rb:</p>
  
  <pre><code>belongs_to :user
  belongs_to :company
  </code></pre>
  
  <p>In Company.rb:</p>
  
  <pre><code>has_many :employments
  has_many :users, :through =&gt; :employments, :dependent =&gt; :destroy
  </code></pre>
  
  <p>This could be possible using something like:</p>
  
  <pre><code>current_user.companies.each{|c| c.users.each {|u| u}}
  </code></pre>
  
  <p>but writing like this I think is much more time consuming.</p>