title: Query if array column contains one or more values
body: <p>I have a Rails 5 application, with a PostgreSQL 9.6 database.</p>
  
  <p>The application has <code>Report</code> model, with a <code>department_ids</code> array field, which is defined in <code>schema.rb</code> as:</p>
  
  <pre><code>t.integer "department_ids", default: [], array: true
  </code></pre>
  
  <p>I need to write a query which returns report rows where the <code>department_ids</code> column contains one or more of a given set of department_ids.</p>
  
  <p>My current workaround is to do this in Ruby with:</p>
  
  <pre><code>department_ids = [2, 5]
  
  reports = Report.all.select do |report|
    (report.department_ids &amp; department_ids).any?
  end
  </code></pre>
  
  <p>However, using <code>select</code> has the downside of returning an <code>Array</code> instead of <code>ActiveRecord::Relation</code>, which means I need to hydrate the filtered results back into <code>ActiveRecord::Relation</code> objects.</p>
  
  <pre><code>Report.where(id: reports.map(&amp;:id))
  </code></pre>
  
  <p>I'd like to avoid that step, and handle this all in a single query.</p>
  
  <p>How can I write query like this with Active Record?</p>