core
core copied to clipboard
New filter setting "Only if parameter is set".
I want to propose the creation of a new filter setting working title "Only if parameter is set". This is meant to be like the "NOT" rules and only wrap one other filter setting. The behaviour should be to check if an attribute name is non empty and then either (to be configurable):
- return an empty result (
[]). - return an abstain result (
null).
This would come in handy and could reduce the amount of custom SQL queries being executed.
do you mean this like http://metamodels.readthedocs.io/de/latest/cookbook/filter/exclusion.html ?
Nope, I meant a wrapper filter which is only executed if there is a value in the parameters.
From your example this would mean only execute if there is a value in the get parameters with the name abteilung.
The problem with your solution is, there is no way to define an execution path (aside from defining very complex queries) of what to do when the parameter has not been set.
Example:
+- OR (with shor circuit / stop after first match)
+ Only if get parameter 'year' is set.
+ Custom SQL: SELECT * FROM {{table}} WHERE year={{param::get?name=year}}
+ Only if get parameter 'month' is set.
+ Custom SQL: SELECT * FROM {{table}} WHERE month={{param::get?name=month}}
+ Custom SQL: SELECT * FROM {{table}} WHERE default=1
So, if you pass the parameter year, it will execute the first query and return it, when passing month, the second will get executed and the last query will get executed if neither matched.
This could become handy and I have a use case for it too.
But what makes the empty result ([] or null), when not using the OR-condition in the example you mentioned before?
An empty result per default will result in an empty result list per default. So it should be configurable to simply ignore the filter rule instead of returning an empty result.
And this filter rule will become useful for wrapping custom sql rules exclusively because you have the "allow empty" checkbox otherwise (?).

That is what I wrote above concerning abstaining (null).
Setting [] as result should be configurable also (but I lack an use case for this).
Ok, I missed that returning null will kick out the filter ~~rule~~ setting.
Yeah then I don't see any further problems.
I meant a wrapper filter which is only executed if there is a value in the parameters.
o.k. - e.g to build a hierarchical set of filters like country, state, city with filter city only have filter city a value and filter state only if country set?
Exactly.
which milestone?
Would love to squeeze it to 2.0.0 but don't know if I find the time for it.
maybe like https://github.com/cboelter/metamodels-filter_condition_membergroup