diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-11-03 23:13:05 +1300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-11-03 23:23:59 +1300 |
commit | 1b47b2147f327537e98bcf42adbcff11180367fe (patch) | |
tree | 247e0a76d213b38757df188475f29a02959c32cf /app/models/clusters/cluster.rb | |
parent | 6f12e3929df987e49427a1355cdf35798f97da65 (diff) | |
download | gitlab-ce-1b47b2147f327537e98bcf42adbcff11180367fe.tar.gz |
Sync `groups` and `group` to fix validation34758-unique-environment-scope
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.
Diffstat (limited to 'app/models/clusters/cluster.rb')
-rw-r--r-- | app/models/clusters/cluster.rb | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 2bd373e0950..e80d35d0f3c 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -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 |