title: Rails Validations: Scoped Uniqueness on a Boolean
body: <p>Based on <a href="https://stackoverflow.com/questions/30384297/activerecord-scoped-uniqueness-validations-vs-mysql-compound-unique-indexes">this previous question that I asked</a>, I understand that it is not possible to use a standard scoped uniqueness on a boolean field. With a boolean you must use an inclusion validation, but then I can't figure out how to scope that inclusion to another field in the table.</p>
  
  <p>Here's the simplest way I can think to describe it.</p>
  
  <p>I have <code>app_settings</code> and <code>app_setting_options</code> tables. The <code>app_settings</code> takes a given <code>app_option_option</code> and either a <code>user_id</code>, <code>user_role_id</code>, <code>group_id</code>, <code>event_id</code>, or <code>app_level</code>. All of them have a scoped uniqueness validation, so there can be only one record with a specific <code>user_id</code> and specific <code>app_setting_option</code>. The problem is that the <code>app_level</code> field is a boolean, I don't know how to scope that uniqueness (true or false) to a <code>app_setting_option</code>.</p>
  
  <p>Here are my validations as is right now:</p>
  
  <pre><code>validates :app_setting_option_id, presence: true
  validates :user_id, uniqueness: { scope: :app_setting_option_id}, allow_nil: true
  validates :user_role_id, uniqueness: { scope: :app_setting_option_id}, allow_nil: true
  validates :group_id, uniqueness: { scope: :app_setting_option_id}, allow_nil: true
  validates :event_id, uniqueness: { scope: :app_setting_option_id}, allow_nil: true
  validates :app_level_setting, inclusion: { in: [true, false] }, allow_nil: true
  </code></pre>
  
  <p>What is the syntax for uniqueness with a scope for that last one?</p>