diff --git a/bijoe/engine.py b/bijoe/engine.py index 0dede1f..1b0c5c0 100644 --- a/bijoe/engine.py +++ b/bijoe/engine.py @@ -163,18 +163,20 @@ class EngineDimension(object): conditions = [] for dimension_name, values in filters: dimension = self.engine_cube.dimensions[dimension_name] - if not (set(dimension.join or []) & set(self.join or [])): + # we build a filter on two sufficient conditions : + # * the filter is on the same dimension as the one we currently query for members, + # * or, the dimension of the filter has impact on a join shared with the current dimension. + if dimension_name != self.name and not (set(dimension.join or []) & set(self.join or [])): continue - # assert dimension.filter condition, values = dimension.build_filter(values) if not condition: continue with self.engine.get_cursor() as cursor: # Ugly... condition = force_text(cursor.mogrify(condition, values)) - if dimension.filter_needs_join and dimension.join: - joins.update(dimension.join) conditions.append(condition) - joins.update(dimension.join) + # add all joins needed by the filter's dimension + if dimension.join: + joins.update(dimension.join) with self.engine.get_cursor() as cursor: sql = self.members_query diff --git a/tests/test_schema1.py b/tests/test_schema1.py index b47edf8..1c0e124 100644 --- a/tests/test_schema1.py +++ b/tests/test_schema1.py @@ -95,7 +95,7 @@ def test_string_dimension(schema1, app, admin): assert get_table(response) == [['String', 'a', 'b', 'c', 'Aucun(e)'], ['number of rows', '11', '2', '3', '1']] form.set('filter__string', ['a', 'b', '__none__']) response = form.submit('visualize') - assert get_table(response) == [['String', 'a', 'b', 'c', 'Aucun(e)'], ['number of rows', '11', '2', '0', '1']] + assert get_table(response) == [['String', 'a', 'b', 'Aucun(e)'], ['number of rows', '11', '2', '1']] def test_string_dimension_json_data(schema1, app, admin):