Multiple relationships found

Hi everyone,

I am facing an error: “Multiple relationships found” when listing Clusters in Manageiq. I can see that this error message appears in the file relationship_mixin.rb. https://github.com/ManageIQ/manageiq/blob/master/app/models/mixins/relationship_mixin.rb

Version: Ivanchuk latest

I guess possibly a duplicate of some fields in the database generated that, but I’m not sure yet. Could you give me a clue of what happened please? Attach evidence of the problem.

I had the same issue and thanks to the help of the gitter folks, I could solve it:

cd /var/www/miq/vmdb/tools
irb

and execute following script:

require File.expand_path(’…/config/environment’, dir)
#resources can have multiple relationships
#each of those should have only 1 parent - bring back the ones with multiple parents
Relationship.where(:resource_type =>‘EmsCluster’).group(:resource_type, :resource_id, :relationship)
.having(“count() > 1”)
.count
.each do |(resource_type, resource_id, relationship), count|
#those were aggregate values. we want the individual relationship records
#order by most recent to older
Relationship.where(:resource_type=>resource_type, :resource_id=>resource_id, :relationship=>relationship)
.includes(:resource).order(:created_at => :desc)
.each_with_index do |rel, index|
puts “>>> #{rel.resource.name} #{rel.created_at} #{rel.ancestry} (#{index == 0 ? ‘keeping’ : ‘destroying’})”
#rel.destroy if index > 0 ### <<< uncomment to execute >>>
end
end

1 Like