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 1 commit
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
15 changes: 15 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,21 @@ 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

# Generates ORDER BY ((SELECT COUNT(*) FROM "vms" WHERE "ext_management_systems"."parent_ems_id" = "vms"."ems_id"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a. is it possible to define this higher up in the inheritance chain?

rewrite:

# 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"
# ))

Copy link
Contributor Author

@Ladas Ladas Feb 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm I think it need to be here, it's specific to NetworkManager (or StorageManager). So any manager that has Vms through :parent_manager

# 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