diff --git a/app/models/persistent_volume.rb b/app/models/persistent_volume.rb index 4593a4b0f8f..198162fe615 100644 --- a/app/models/persistent_volume.rb +++ b/app/models/persistent_volume.rb @@ -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 diff --git a/spec/models/persistent_volume_spec.rb b/spec/models/persistent_volume_spec.rb index 52e5058089e..b62a15b4a60 100644 --- a/spec/models/persistent_volume_spec.rb +++ b/spec/models/persistent_volume_spec.rb @@ -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