|
@@ -6,7 +6,7 @@ import copy
|
6
|
6
|
import leapi
|
7
|
7
|
from leapi.leobject import REL_SUB, REL_SUP
|
8
|
8
|
|
9
|
|
-from leapi.lecrud import _LeCrud
|
|
9
|
+from leapi.lecrud import _LeCrud, REL_SUP, REL_SUB
|
10
|
10
|
|
11
|
11
|
from mosql.db import Database, all_to_dicts, one_to_dict
|
12
|
12
|
from mosql.query import select, insert, update, delete, join, left_join
|
|
@@ -107,7 +107,24 @@ class LeDataSourceSQL(DummyDatasource):
|
107
|
107
|
if offset:
|
108
|
108
|
kwargs['offset'] = offset
|
109
|
109
|
|
110
|
|
- # @todo implement relational filters
|
|
110
|
+ # relational filters
|
|
111
|
+ # @todo this only works with hierarchy relations
|
|
112
|
+ if rel_filters:
|
|
113
|
+ le_relation = target_cls.name2class('LeRelation')
|
|
114
|
+ rel_cpt = 0
|
|
115
|
+ for rel_filter in rel_filters:
|
|
116
|
+ rel_cpt += 1
|
|
117
|
+ rel_name = 'rel' + str(rel_cpt)
|
|
118
|
+ name, op, value = rel_filter
|
|
119
|
+ direction, nature = name
|
|
120
|
+ if direction == REL_SUP:
|
|
121
|
+ join_column, filter_column = (le_relation._subordinate_field_name, le_relation._superior_field_name)
|
|
122
|
+ else:
|
|
123
|
+ join_column, filter_column = (le_relation._superior_field_name, le_relation._subordinate_field_name)
|
|
124
|
+ rel_join = left_join(utils.common_tables['relation'] + ' as ' + rel_name, {utils.column_prefix(main_table, main_class.uidname()):utils.column_prefix(rel_name, join_column)})
|
|
125
|
+ filters.append((utils.column_prefix(rel_name, 'nature'), '=', nature))
|
|
126
|
+ filters.append((utils.column_prefix(rel_name, filter_column), op, value))
|
|
127
|
+ joins.append(rel_join)
|
111
|
128
|
|
112
|
129
|
# prefix filters'' column names, and prepare dict for mosql where {(fieldname, op): value}
|
113
|
130
|
wheres = {(utils.find_prefix(name, fields), op):value for name,op,value in filters}
|