I accidentally created duplicate relationships... now I need to delete them. We got some crazy stuff going on in a cypher answer here how do I delete duplicate relationships between two nodes with cypher?
At first my mind wandered to finding the relationship then checking the count on it. But that's only if I know the two nodes already.
Thoughts?
Update
Maybe I'm missing something, but I don't think this would give me an indication of duplication
user.friends.count > 1
as this will count the nodes. I wouldn't know which nodes are counted twice
The only way I can think of getting the other user is to do a second loop. I think this might work if first_rel_to
and match_to
could be used directly on user without a queryproxy
User.all.each do |user|
user.friends.each do |friend|
user.first_rel_to(friend).destroy if (user.match_to(friend).count > 1)
end
end
So.. does this have to be done...?
Answer: Yes this has to be done
User.all.each do |user|
user.friends.each do |friend|
user.friends.first_rel_to(friend).destroy if (user.friends.match_to(friend).count > 1)
end
end