title: How does the upsert function in Rails work?
body: <p>As upsert is a 'newer' function that has been implemented in Rails’ ActiveRecord, there is not a lot of documentation behind it. I do understand the concept behind it, as its purpose is to insert a new record if it is a new record and update existing records if it is found in the database.</p>
  
  <p>So for instance, when I call: <code>Model.upsert(name: 'a', number: 1)</code>, does ActiveRecord look for a preexisting record with the name: 'a' or a preexisting record with the number: 1?</p>
  
  <p>For example, right now when I am trying to update a Model with the name a using <code>Model.upsert(name: 'a', number: 1)</code>, I get a <code>NotNullViolation</code>, because there is a null value in an id that I am not specifying. Can I update a model with upsert without passing in the id as a parameter?</p>