From 7201ab40d3c6bf170ee64db95bf7a61024f752cf Mon Sep 17 00:00:00 2001 From: Keenan Brock Date: Tue, 11 Jul 2023 11:31:15 -0400 Subject: [PATCH] assign container_project inverse_of values when fetching container groups from a container_project, it was not assigning the reverse association added `inverse_of` to get them assigned (and avoid N+1) changed ext_management_system class to one that had the `container_projects` reference --- app/models/container_project.rb | 6 +++--- spec/models/container_project_spec.rb | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/models/container_project.rb b/app/models/container_project.rb index 78ebee4fd066..84bc4e4db0ec 100644 --- a/app/models/container_project.rb +++ b/app/models/container_project.rb @@ -8,15 +8,15 @@ class ContainerProject < ApplicationRecord include TenantIdentityMixin include CustomActionsMixin include_concern 'Purging' - belongs_to :ext_management_system, :foreign_key => "ems_id" - has_many :container_groups, -> { active } + belongs_to :ext_management_system, :class_name => "ContainerManager", :foreign_key => "ems_id", :inverse_of => :container_projects + has_many :container_groups, -> { active }, :inverse_of => :container_project has_many :container_routes has_many :container_replicators has_many :container_services has_many :containers, :through => :container_groups has_many :container_images, -> { distinct }, :through => :container_groups has_many :container_nodes, -> { distinct }, :through => :container_groups - has_many :container_quotas, -> { active } + has_many :container_quotas, -> { active }, :inverse_of => :container_project has_many :container_quota_scopes, :through => :container_quotas has_many :container_quota_items, :through => :container_quotas has_many :container_limits diff --git a/spec/models/container_project_spec.rb b/spec/models/container_project_spec.rb index cca24282d6aa..a44235509412 100644 --- a/spec/models/container_project_spec.rb +++ b/spec/models/container_project_spec.rb @@ -31,6 +31,9 @@ groups = project.container_groups.to_a expect(groups).to match_array([group_active]) + expect do + expect(groups.first.container_project).to eq(project) + end.not_to make_database_queries end end end