Commit 1b47b214 authored by Thong Kuah's avatar Thong Kuah

Sync `groups` and `group` to fix validation

Otherwise adding to `groups` will cause validation (in EE)  based on
`group` to fail.

This is consistent with how Clusters::Cluster#first_project. The
alternative is to switch validation to use `groups` as well.
parent 6f12e392
......@@ -3,6 +3,7 @@
module Clusters
class Cluster < ActiveRecord::Base
include Presentable
include Gitlab::Utils::StrongMemoize
self.table_name = 'clusters'
......@@ -24,9 +25,6 @@ module Clusters
has_many :cluster_groups, class_name: 'Clusters::Group'
has_many :groups, through: :cluster_groups, class_name: '::Group'
has_one :cluster_group, -> { order(id: :desc) }, class_name: 'Clusters::Group'
has_one :group, through: :cluster_group, class_name: '::Group'
# we force autosave to happen when we save `Cluster` model
has_one :provider_gcp, class_name: 'Clusters::Providers::Gcp', autosave: true
......@@ -119,12 +117,19 @@ module Clusters
end
def first_project
return @first_project if defined?(@first_project)
@first_project = projects.first
strong_memoize(:first_project) do
projects.first
end
end
alias_method :project, :first_project
def first_group
strong_memoize(:first_group) do
groups.first
end
end
alias_method :group, :first_group
def kubeclient
platform_kubernetes.kubeclient if kubernetes?
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment