From e2d79a03f2879c3c0f69f8bceb2bba23054c04d4 Mon Sep 17 00:00:00 2001
From: Mateus Rambo Strey <mars11@inf.ufpr.br>
Date: Tue, 10 Nov 2015 15:49:08 -0200
Subject: [PATCH] verify if user relationship exists before add or remove

---
 app/repositories/orient_db/institution_repository.rb | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/app/repositories/orient_db/institution_repository.rb b/app/repositories/orient_db/institution_repository.rb
index 60769dd99..4fbcfbf57 100644
--- a/app/repositories/orient_db/institution_repository.rb
+++ b/app/repositories/orient_db/institution_repository.rb
@@ -27,12 +27,17 @@ module OrientDb
     end
 
     def add_user(user, institution)
-      create_edge "BelongsTo", user.rid, institution.id
+      unless edge_exists? "BelongsTo", user.rid, institution.id
+        create_edge "BelongsTo", user.rid, institution.id
+      end
+
       institution
     end
 
     def remove_user(user, institution)
-      destroy_edge "BelongsTo", user.rid, institution.id
+      if edge_exists? "BelongsTo", user.rid, institution.id
+        destroy_edge "BelongsTo", user.rid, institution.id
+      end
     end
 
     def build_object(args={})
-- 
GitLab