diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 18:09:21 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-27 18:09:21 +0000 |
commit | e0fa0638a422c3e20d4423c9bb69d79afc9c7d3d (patch) | |
tree | 9abb3c0706576bbda895fe9539a55556930606e2 /app/models/ci/ref.rb | |
parent | f8d15ca65390475e356b06dedc51e10ccd179f86 (diff) | |
download | gitlab-ce-e0fa0638a422c3e20d4423c9bb69d79afc9c7d3d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/ci/ref.rb')
-rw-r--r-- | app/models/ci/ref.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/models/ci/ref.rb b/app/models/ci/ref.rb new file mode 100644 index 00000000000..a0782bc0444 --- /dev/null +++ b/app/models/ci/ref.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Ci + class Ref < ApplicationRecord + extend Gitlab::Ci::Model + + STATUSES = %w[success failed fixed].freeze + + belongs_to :project + belongs_to :last_updated_by_pipeline, foreign_key: :last_updated_by_pipeline_id, class_name: 'Ci::Pipeline' + # ActiveRecord doesn't support composite FKs for this reason we have to do the 'unscope(:where)' + # hack. + has_many :pipelines, ->(ref) { + # We use .read_attribute to save 1 extra unneeded query to load the :project. + unscope(:where) + .where(ref: ref.ref, project_id: ref.read_attribute(:project_id), tag: ref.tag) + # Sadly :inverse_of is not supported (yet) by Rails for composite PKs. + }, inverse_of: :ref_status + + validates :status, inclusion: { in: STATUSES } + validates :last_updated_by_pipeline, presence: true + end +end |