core icon indicating copy to clipboard operation
core copied to clipboard

New filter setting "Only if parameter is set".

Open discordier opened this issue 8 years ago • 10 comments

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):

  1. return an empty result ([]).
  2. return an abstain result (null).

This would come in handy and could reduce the amount of custom SQL queries being executed.

discordier avatar Feb 23 '17 16:02 discordier

do you mean this like http://metamodels.readthedocs.io/de/latest/cookbook/filter/exclusion.html ?

zonky2 avatar Feb 23 '17 20:02 zonky2

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.

discordier avatar Feb 25 '17 09:02 discordier

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 (?). bildschirmfoto 2017-02-25 um 12 04 55

richardhj avatar Feb 25 '17 11:02 richardhj

That is what I wrote above concerning abstaining (null). Setting [] as result should be configurable also (but I lack an use case for this).

discordier avatar Feb 25 '17 12:02 discordier

Ok, I missed that returning null will kick out the filter ~~rule~~ setting. Yeah then I don't see any further problems.

richardhj avatar Feb 25 '17 13:02 richardhj

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?

zonky2 avatar Feb 26 '17 16:02 zonky2

Exactly.

discordier avatar Feb 26 '17 18:02 discordier

which milestone?

zonky2 avatar Mar 07 '17 21:03 zonky2

Would love to squeeze it to 2.0.0 but don't know if I find the time for it.

discordier avatar Mar 07 '17 21:03 discordier

maybe like https://github.com/cboelter/metamodels-filter_condition_membergroup

zonky2 avatar Jan 21 '23 15:01 zonky2