diff --git a/app/models/relationship.rb b/app/models/relationship.rb index c704164ae..e9a59c5e8 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -157,8 +157,8 @@ def create_or_update_parent_id end def self.create_unless_exists(source_id, target_id, relationship_type, options = {}) - r = Relationship.where(source_id: source_id, target_id: target_id).where('relationship_type = ?', relationship_type.to_yaml).last - r = Relationship.where(target_id: target_id).last if r.nil? + r = Relationship.where(target_id: target_id).where.not(source_id: source_id).last + r = Relationship.where(source_id: source_id, target_id: target_id).where('relationship_type = ?', relationship_type.to_yaml).last unless r.nil? exception_message = nil exception_class = nil if r.nil?