Browse Source

[#61] Corrected the relational filters parsing method in LeDataSourceSQL

Roland Haroutiounian 9 years ago
parent
commit
e3dba75747
1 changed files with 12 additions and 6 deletions
  1. 12
    6
      leobject/datasources/ledatasourcesql.py

+ 12
- 6
leobject/datasources/ledatasourcesql.py View File

@@ -13,6 +13,8 @@ class LeDataSourceSQL(DummyDatasource):
13 13
 
14 14
     RELATIONS_TABLE_NAME = 'relations'
15 15
     RELATIONS_POSITIONS_FIELDS = {REL_SUP:'superior_id', REL_SUB:'subordinate_id'}
16
+    RELATIONS_NATURE_FIELD = 'nature'
17
+
16 18
     MODULE = 'sqlite3'
17 19
 
18 20
     def __init__(self, module=None, *conn_args, **conn_kargs):
@@ -85,20 +87,24 @@ class LeDataSourceSQL(DummyDatasource):
85 87
         if relational_filters or len(relational_filters) > 0:
86 88
             for relational_filter in relational_filters:
87 89
                 # Parsing the relation_filter
88
-                relational_position = relational_filter[0][0]
89
-                relational_field = relational_filter[0][1]
90
+                relational_position = REL_SUB if relational_filter[0][0] == REL_SUP else REL_SUP
91
+                relational_nature = relational_filter[0][1]
90 92
                 relational_operator = relational_filter[1]
91
-                relational_value = relational_filter[2]
92
-                relational_where_filters_key = (relational_field, relational_operator)
93
-                relational_where_filters_value = relational_value
93
+
94
+                relational_condition_key = (self.RELATIONS_POSITIONS_FIELDS[relational_filter[0][0]], relational_operator)
95
+                relational_condition_value = relational_filter[2]
94 96
 
95 97
                 # Definition of the join condition
96 98
                 relation_table_join_field = "%s.%s" % (self.RELATIONS_TABLE_NAME, self.RELATIONS_POSITIONS_FIELDS[relational_position])
97 99
                 query_table_join_field = "%s.lodel_id" % query_table_name
98 100
                 join_fields[query_table_join_field] = relation_table_join_field
99 101
 
102
+                # Adding to "where" filters
103
+                where_filters['%s.%s' % (self.RELATIONS_TABLE_NAME,self.RELATIONS_NATURE_FIELD_NAME ]
104
+
100 105
                 # Adding "where" filters
101
-                where_filters[relational_where_filters_key] = relational_where_filters_value
106
+                where_filters['%s.%s' % (self.RELATIONS_TABLE_NAME, self.RELATIONS_NATURE_FIELD)] = relational_field
107
+                where_filters[relational_condition_key] = relational_condition_value
102 108
 
103 109
             # Building the query
104 110
             query = select(query_table_name, where=where_filters, select=field_list, joins=join(self.RELATIONS_TABLE_NAME, join_fields))

Loading…
Cancel
Save