title: Conditionally validating uniqueness of a boolean in Rails
body: <p>I'm trying to validate the uniqueness of a boolean field, but only when it's true. I have the following defined in my model:</p>
  
  <pre><code>validates_uniqueness_of :org_feed, if: :org_feed
  </code></pre>
  
  <p>When this validation runs, it generates the following SQL:</p>
  
  <pre><code>SELECT 1 AS one FROM `feeds` WHERE `feeds`.`org_feed` = BINARY 't' LIMIT 1
  </code></pre>
  
  <p>But, this query returns a row when it finds a feed where the boolean org_feed is <code>0</code>, which is the exact opposite of what it should do. I would expect the <code>BINARY 't'</code> to just be <code>true</code> since the field is a boolean. Thus, I feel like the query should look like this instead:</p>
  
  <pre><code>SELECT 1 AS one FROM `feeds` WHERE `feeds`.`org_feed` = true LIMIT 1
  </code></pre>
  
  <p>Do I need to tell the validation that this is a boolean field somehow? </p>