title: How to use scopes to join across multiple tables
body: <p>I am new to ROR and I am trying to understand scopes. In my current implementation I am getting all the Processors and displaying it in the view. </p>
  
  <pre><code>class ProcessorsController
    def index
      @processors = Processor.all    
    end
  end
  </code></pre>
  
  <p><strong>I want to modify this so I can get only the processors where the user is admin</strong>. This is how my relations are set up.</p>
  
  <pre><code>class Processor
    belongs_to :feed
  
    #SCOPES (what I have done so far)
    scope :feed, joins(:feed)
    scope :groups, joins(:feed =&gt; :groups).join(:user).where(:admin =&gt; true)
  end
  
  class Feed &lt; ActiveRecord::Base
    has_and_belongs_to_many :groups
  end
  
  class Group &lt; ActiveRecord::Base
    belongs_to :user
  end
  
  class User &lt; ActiveRecord::Base
    has_many :groups
    scope :admin,     where(:admin     =&gt; true)
  end
  </code></pre>
  
  <p>I was able to do this in my pry</p>
  
  <pre><code>pry(main)&gt; Processor.find(63).feed.groups.first.user.admin?
  </code></pre>
  
  <p>PS: could someone provide some good resources where I could learn how to use scopes if the relationships are complex. </p>