title: Rails scope using has_many association
body: <p>I have three models defined as below:</p>
  
  <pre><code>class Parent &lt; ActiveRecord::Base
    has_many :kids
    has_many :restrictions
  
    def has_valid_restriction?
      self.restrictions.where(:type =&gt; 1).size &gt; 0
    end
  end
  
  class Kid &lt; ActiveRecord::Base
    belongs_to :parent
    has_many :restrictions
  
    scope :valid, -&gt; {
      includes(:restrictions).where("restriction.type = 1")
    }
  end
  
  class Restriction &lt; ActiveRecord::Base
    belongs_to :restricted_object #this can be kid or parent
  end
  </code></pre>
  
  <p>Kid has a scope called 'valid' which chooses the Kids having a restriction with type 1. I want to add a similar scope to Parent which chooses Parents which either have a restriction of type one or a valid Kid (i.e. a Kid with restriction of type 1).</p>
  
  <p>How can I create such a scope?</p>