Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-02-05 17:41:00 +0300
committerSean McGivern <sean@gitlab.com>2019-02-05 17:41:00 +0300
commitd6be539bf1be90d81ac4ad7aac94aedebac10c43 (patch)
tree96993829bc0d4437ddf6363afa3aed710a824ea5 /app
parent5dc15b2a3b5fee22bb905c1e178e3ea6300d02c3 (diff)
parentccd8a9b2821c964b85533c253430041712ef195e (diff)
Merge branch 'bvl-codeowner-rules-model-ce' into 'master'
Adds helper for `find_or_create_by` in transaction See merge request gitlab-org/gitlab-ce!24913
Diffstat (limited to 'app')
-rw-r--r--app/models/application_record.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/models/application_record.rb b/app/models/application_record.rb
index 29696ab276f..c4e310e638d 100644
--- a/app/models/application_record.rb
+++ b/app/models/application_record.rb
@@ -6,4 +6,12 @@ class ApplicationRecord < ActiveRecord::Base
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