|
@@ -7,8 +7,9 @@ from leobject.leobject import REL_SUB, REL_SUP
|
7
|
7
|
|
8
|
8
|
from mosql.db import Database, all_to_dicts
|
9
|
9
|
from mosql.query import select, insert, update, delete, join
|
10
|
|
-from mosql.util import raw
|
|
10
|
+from mosql.util import raw, or_
|
11
|
11
|
import mosql.mysql
|
|
12
|
+
|
12
|
13
|
from DataSource.MySQL.MySQL import MySQL
|
13
|
14
|
|
14
|
15
|
|
|
@@ -239,23 +240,25 @@ class LeDataSourceSQL(DummyDatasource):
|
239
|
240
|
|
240
|
241
|
return True
|
241
|
242
|
|
242
|
|
- ## @brief Return all relation of a lodel_id given a position and a nature
|
243
|
|
- # @param lodel_id int : We want the relations of this lodel_id
|
244
|
|
- # @param superior bool : If true search the relations where lodel_id is in id_sup
|
245
|
|
- # @param nature str|None : Search for relations with the given nature (if None rel2type)
|
246
|
|
- # @param return an array of dict with keys [ id_sup, id_sub, rank, depth, nature ]
|
247
|
|
- def get_relations(self, lodel_id, superior=True, nature=None):
|
248
|
|
- select_params = {}
|
249
|
|
- if superior is True:
|
250
|
|
- select_params['id_sup'] = lodel_id
|
251
|
|
- else:
|
252
|
|
- select_params['id_sub'] = lodel_id
|
253
|
|
-
|
254
|
|
- select_params['nature'] = nature
|
|
243
|
+ ## @brief Fetch all relations concerning an object (rel2type relations)
|
|
244
|
+ # @param leo LeType : LeType child instance
|
|
245
|
+ # @return a list of tuple (lesup, lesub, dict_attr)
|
|
246
|
+ def get_relations(self, leo):
|
255
|
247
|
|
256
|
|
- sql = select(self.datasource_utils.relations_table_name, select_params)
|
|
248
|
+ sql = select(self.datasource_utils.relations_table_name, where=or_(({'id_sub':leo.lodel_id},{'id_sup':leo.lodel_id})))
|
257
|
249
|
|
258
|
250
|
with self.connection as cur:
|
259
|
251
|
results = all_to_dicts(cur.execute(sql))
|
260
|
252
|
|
261
|
|
- return results
|
|
253
|
+ relations = []
|
|
254
|
+ for result in results:
|
|
255
|
+ id_sup = result['id_sup']
|
|
256
|
+ id_sub = result['id_sub']
|
|
257
|
+
|
|
258
|
+ del result['id_sup']
|
|
259
|
+ del result['id_sub']
|
|
260
|
+ rel_attr = result
|
|
261
|
+
|
|
262
|
+ relations.append((id_sup, id_sub, rel_attr))
|
|
263
|
+
|
|
264
|
+ return relations
|