Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering by VMs in NetworkManagers list #14092

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions app/models/manageiq/providers/network_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ class << model_name
has_many :load_balancer_health_checks, :foreign_key => :ems_id, :dependent => :destroy
has_many :load_balancer_health_check_members, :through => :load_balancer_health_checks

# Uses "ext_management_systems"."parent_ems_id" instead of "ext_management_systems"."id"
#
# ORDER BY ((
# SELECT COUNT(*)
# FROM "vms"
# WHERE "ext_management_systems"."parent_ems_id" = "vms"."ems_id"
# ))
#
# So unlike the parent class definition, this looks at "ext_management_systems"."parent_ems_id" instead of
# "ext_management_systems"."id"
# If we are able to define a has_many :vms, :through => :parent_manager, that does actual join, this code should
# not be needed.
virtual_total :total_vms, :vms, {
:arel => lambda do |t|
foreign_table = Vm.arel_table
local_key = :parent_ems_id
foreign_key = :ems_id
arel_column = Arel.star.count
t.grouping(foreign_table.project(arel_column).where(t[local_key].eq(foreign_table[foreign_key])))
end
}

alias all_cloud_networks cloud_networks

belongs_to :parent_manager,
Expand Down