title: Can I query a record with multiple associated records that fit certain criteria?
body: <p>I have two tables, <code>Show</code>, <code>Character</code>. Each Show has_many Characters.</p>
  
  <pre><code>class Show &lt; ActiveRecord::Base
    has_many :characters
  
  class Character &lt; ActiveRecord::Base
    belongs_to :show
  </code></pre>
  
  <p>What I want to do is return the results of a Show that is associated with multiple Characters that fit certain criteria.</p>
  
  <p>For example, I want to be able to return a list of Shows that have as characters both Batman and Robin. Not Batman OR Robin, Batman AND Robin.</p>
  
  <p>So the query should be something like</p>
  
  <pre><code>Show.includes(:characters).where(characters: {'name = ? AND name = ?', "Batman", "Robin"})
  </code></pre>
  
  <p>But this returns an error. Is there a syntax for this that would work?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The query</p>
  
  <pre><code>Show.includes(:characters).where('characters.name = ? AND characters.name = ?', "Batman", "Robin")
  </code></pre>
  
  <p>returns a value of 0, even though there are definitely Shows associated with both Batman and Robin.</p>