title: Active Record Validations: Uniqueness of a calculated field while inserting it
body: <p>I have a model with a calculated field that must be unique:</p>
  <pre class="lang-rb prettyprint-override"><code>class MyModel &lt; ApplicationRecord
   before_save :set_unique_identifier
  
   validates :unique_identifier, uniqueness: true
  
   private
  
   def set_unique_identifier
      some calculation...
      self.unique_identifier = the calculations.. (THIS IS A STRING)
   end
  
  end  
  </code></pre>
  <p>Active Record is letting me to create the records having the same unique_identifier.</p>
  <p>The <code>validates :unique_identifier, uniqueness: true</code> is being triggered only when I update the record.</p>
  <p>How to validate it in the moment of insertion?</p>