debian-mirror-gitlab/app/models/application_record.rb

24 lines
487 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
2019-03-02 22:35:43 +05:30
def self.id_in(ids)
where(id: ids)
end
def self.safe_find_or_create_by!(*args)
safe_find_or_create_by(*args).tap do |record|
record.validate! unless record.persisted?
end
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
2019-02-15 15:39:39 +05:30
end