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.
So for instance, when I call: Model.upsert(name: 'a', number: 1)
, does ActiveRecord look for a preexisting record with the name: 'a' or a preexisting record with the number: 1?
For example, right now when I am trying to update a Model with the name a using Model.upsert(name: 'a', number: 1)
, I get a NotNullViolation
, 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?