Browse Source

[#74] del_related method is usable in LeDataSourceSQL

Roland Haroutiounian 9 years ago
parent
commit
aaa4268afa
2 changed files with 27 additions and 1 deletions
  1. 7
    0
      leobject/datasources/dummy.py
  2. 20
    1
      leobject/datasources/ledatasourcesql.py

+ 7
- 0
leobject/datasources/dummy.py View File

@@ -103,6 +103,13 @@ class DummyDatasource(object):
103 103
     def get_related(self, leo, letype, get_sub=True):
104 104
         pass
105 105
 
106
+    ## @brief Delete a relation between 2 LeType
107
+    # @param lesup LeType
108
+    # @param lesub LeType
109
+    # @return True if success else return False
110
+    def del_related(self, lesup, lesub):
111
+        pass
112
+
106 113
     ## @brief Fetch a relation
107 114
     # @param id_relation int : The relation identifier
108 115
     # @return a dict{'id_relation':.., 'lesup':.., 'lesub':.., < if exists 'dict_attr':..>}

+ 20
- 1
leobject/datasources/ledatasourcesql.py View File

@@ -224,7 +224,26 @@ class LeDataSourceSQL(DummyDatasource):
224 224
                 cur.execute(sql)
225 225
         self._set_relation_rank(id_relation, rank)
226 226
         return relation_id
227
-    
227
+
228
+    ## @brief Deletes the relation between 2 LeType
229
+    # @param lesup LeType
230
+    # @param lesub LeType
231
+    # @return True if success else False
232
+    def del_related(self, lesup, lesub):
233
+        with self.connection as cur:
234
+            sql = delete(
235
+                self.datasource_utils.relations_table_name,
236
+                {
237
+                    'id_sup': lesup.lodel_id,
238
+                    'id_sub': lesub.lodel_id
239
+                }
240
+            )
241
+
242
+            if cur.execute(sql) != 1:
243
+                return False
244
+
245
+        return True
246
+
228 247
     ## @brief Set the rank of a relation identified by its ID
229 248
     # @param id_relation int : relation ID
230 249
     # @param rank int|str : 'first', 'last', or an integer value

Loading…
Cancel
Save