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