gitlab-org--gitlab-foss/app/models/application_record.rb
Bob Van Landuyt ccd8a9b282 Adds helper for find_or_create_by in transaction
This allows us to call `find_or_create_by` on all models and scopes.
2019-02-05 14:44:41 +01:00

17 lines
332 B
Ruby

# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def self.id_in(ids)
where(id: ids)
end
def self.safe_find_or_create_by(*args)
transaction(requires_new: true) do
find_or_create_by(*args)
end
rescue ActiveRecord::RecordNotUnique
retry
end
end