title: validates uniqueness: { scope: [:foobar] } not working
body: <p>I have a model that has a uniqueness validation on it something like:</p>
  
  <pre><code>class CurriculumRequirement &lt; ActiveRecord::Base
  
    belongs_to :student
  
    belongs_to :curriculum_sequence
  
    validates :student_id,
      uniqueness: { scope: [:curriculum_sequence_id] }
  end 
  </code></pre>
  
  <p>The problem is that somehow duplicate records are being inserted into my database despite this validation. The place in which adding these records happens in a sidekiq background worker: </p>
  
  <p><code>student.curriculum_requirements.where(curriculum_sequence: sequence).first_or_create</code></p>
  
  <p>I <em>think</em> that what is happening is that 2 or more workers are executing the same code, and saving the record. Is there a way to put a lock or something on this record so that I don't get duplicates?</p>