Commit 524eef7d authored by Thong Kuah's avatar Thong Kuah

Merge branch '31851-set-inverse_of-on-clusters-applications-association' into 'master'

Resolve "Set `inverse_of` on Clusters <-> Applications association"

See merge request gitlab-org/gitlab!17285
parents d682be1f e898c89e
......@@ -39,7 +39,7 @@ module Clusters
def self.has_one_cluster_application(name) # rubocop:disable Naming/PredicateName
application = APPLICATIONS[name.to_s]
has_one application.association_name, class_name: application.to_s # rubocop:disable Rails/ReflectionClassName
has_one application.association_name, class_name: application.to_s, inverse_of: :cluster # rubocop:disable Rails/ReflectionClassName
end
has_one_cluster_application :helm
......
......@@ -38,6 +38,15 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to respond_to :project }
describe 'applications have inverse_of: :cluster option' do
let(:cluster) { create(:cluster) }
let!(:helm) { create(:clusters_applications_helm, cluster: cluster) }
it 'does not do a third query when referencing cluster again' do
expect { cluster.application_helm.cluster }.not_to exceed_query_limit(2)
end
end
describe '.enabled' do
subject { described_class.enabled }
......
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