Skip to content

Commit

Permalink
assign container_project inverse_of values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kbrock committed Jul 11, 2023
1 parent c63bf80 commit 7201ab4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/models/container_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/models/container_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7201ab4

Please sign in to comment.