Add Rails 6 note here

This commit is contained in:
Sam 2018-08-21 11:08:58 +10:00
parent 45cd141ed6
commit 57d04200a1

View File

@ -3,6 +3,16 @@ class ActiveRecord::Base
# Handle PG::UniqueViolation as well due to concurrency
# find_or_create does find_by(hash) || create!(hash)
# in some cases find will not find and multiple creates will be called
#
# note: Rails 6 has: https://github.com/rails/rails/blob/c83e30da27eafde79164ecb376e8a28ccc8d841f/activerecord/lib/active_record/relation.rb#L171-L201
# This means that in Rails 6 we would either use:
#
# create_or_find_by! (if we are generally creating)
#
# OR
#
# find_by(hash) || create_or_find_by(hash) (if we are generally finding)
#
def self.find_or_create_by_safe!(hash)
begin
find_or_create_by!(hash)