Upsert in Rails ActiveRecord

Jason Swett picture Jason Swett · Jan 14, 2011 · Viewed 22.7k times · Source

Does ActiveRecord have a built-in upsert functionality? I know I could write it myself but I obviously don't want to if such a thing already exists.

Answer

Chris picture Chris · Jun 25, 2019

There is an awesome new feature in rails 6: they added upsert and upsert_all to ActiveRecord

More info can be found here https://edgeapi.rubyonrails.org/classes/ActiveRecord/Persistence/ClassMethods.html#method-i-upsert_all