Patch included below.
I need to filter some content based on a value which when it's TRUE is a value in a table connected through LEFT JOIN and when it's FALSE has no row in the connected table - in other words all it's values are NULL.
The current boolean filter - views_handler_filter_boolean_operator - doesn't consider NULL as FALSE but neither considers it as TRUE. Since my FALSE is NULL I can't filter on FALSE values.
I'm attaching a patch which introduced a possibility to define that a boolean filter should treat NULL as FALSE.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 508124-fix-accept_null.patch | 666 bytes | dawehner |
| #5 | views_filter_boolean_null_fix_issue_508124_5.patch | 3.58 KB | voxpelli |
| views_filter_boolean_null_fix.patch | 3.58 KB | voxpelli |
Comments
Comment #1
dawehneri would like perhaps to have this also as a option for gui.
This would be for sure a simple patch for this patch :)
PS: the patch should be out of views root dir.
Comment #2
voxpelli commented@dereine: I'm not sure how it would fit in the gui. The handlers are used to describe data for views and whether to treat null as false or not depends on the data structure which I believe the gui never has any part in defining? Can you give an example of how it could fit in the gui?
If I need to reroll the patch out of the views module I'll do that later when I'm back at work.
Comment #3
dawehnerUpdated i developed one simplehandler for a custom module using this feature and it worked as expected
Query before
Query after:
i think the difference is easy to see
Comment #4
merlinofchaos commentedIn definitions, I try to avoid underscores. So it should be 'accept null' rather than 'accept_null'.
I'm trying to decide if I would want a checkbox or not to accept NULL, but I think I'm agreeing that it does not need to be a UI element.
Comment #5
voxpelli commentedRerolling the patch with 'accept null' - it became the wrong patch this time as well. I'm making the patch through git so I probably needs to generate it with some other settings - have to look that up.
Not considering the path in my patch - does it work well or do I really need to improve on the style of them? What do you think merlinofchaos?
Comment #6
merlinofchaos commentedCommited to 2.x and 3.x branches.
Comment #8
fonant commentedThis is broken in the released Views code, but is useful for me: I also want to filter on whether a related table field exists or is NULL, so I can filter on the existence of the cross-table link.
The released code tests for the configuration setting with:
if (isset($this->definition['accept_null']))but then uses the value of the setting without the underscore:
$this->accept_null = (bool) $this->definition['accept null'];The fix is trivial: remove the underscore from the test string.
The workaround is simply to add both 'accept null' and 'accept_null' if you need this set to TRUE in hook_views_data().
Comment #9
fonant commentedComment #10
dawehnerHere is a patch
Comment #11
EPO commentedThe same problem occurs when using a negativ argument filter i.e. checking "exclude argument". If there are null values in the column the null rows are regarded as having(!) the excluded value. This is commonly not desired.
The SQL Code is
... WHERE field != 'x' ...
and should be
... WHERE field != 'x' OR field IS NULL
Sorry, but I am not responsible for his ugly SQL behaviour.
Comment #12
merlinofchaos commentedAfter consideration, #11 is separate from this issue, though it's similar. That issue is about arguments, and the patch here is about filters.
Comment #13
merlinofchaos commented#10 committed to all branches.