Skip to content

Commit

Permalink
explicitly state PersistentVolume#parent is an Ems
Browse files Browse the repository at this point in the history
this allows us to define a virtual attribute delegation

|     ms |query | qry ms |     rows |` comments`
|    ---:|  ---:|   ---:|      ---:|  ---
|  278.6 |   31 |  12.7 |       48 |` /persistent_volume/report_data#before`
|  258.7 |   11 |   9.9 |       28 |` /persistent_volume/report_data#after`
|   7.1% |   65%|  22.0%|      42% | diff
  • Loading branch information
kbrock committed Aug 1, 2023
1 parent be59dd4 commit eb5e4ee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/models/persistent_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ class PersistentVolume < ContainerVolume
acts_as_miq_taggable
include NewWithTypeStiMixin
serialize :capacity, Hash
delegate :name, :to => :parent, :prefix => true, :allow_nil => true

# NOTE: overriding parent polymorphic. Ensuring the type gets set
belongs_to :parent, :class_name => 'ExtManagementSystem'
default_value_for :parent_type, 'ExtManagementSystem'

has_many :container_volumes, -> { where(:type => 'ContainerVolume') }, :through => :persistent_volume_claim
has_many :parents, -> { distinct }, :through => :container_volumes, :source_type => 'ContainerGroup'
alias_attribute :container_groups, :parents

virtual_attribute :parent_name, :string
virtual_delegate :name, :to => :parent, :prefix => true, :allow_nil => true, :type => :string
virtual_attribute :storage_capacity, :string

def storage_capacity
Expand Down
2 changes: 1 addition & 1 deletion spec/models/persistent_volume_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
end

# delegating through a polymorphic forces us to ruby only
it_behaves_like "ruby only virtual_attribute", :parent_name, 'ems_name'
it_behaves_like "sql friendly virtual_attribute", :parent_name, 'ems_name'
end
end

0 comments on commit eb5e4ee

Please sign in to comment.