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.

Comments

dawehner’s picture

i 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.

voxpelli’s picture

@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.

dawehner’s picture

Updated i developed one simplehandler for a custom module using this feature and it worked as expected

Query before

SELECT node.nid AS nid,
   custom.field AS custom_field,
   node.title AS node_title,
   node.created AS node_created
 FROM node node 
 LEFT JOIN custom custom ON node.nid = custom.nid
 WHERE custom.field = 0
   ORDER BY node_created DESC

Query after:

SELECT node.nid AS nid,
   custom.field AS custom_field,
   node.title AS node_title,
   node.created AS node_created
 FROM node node 
 LEFT JOIN custom custom ON node.nid = custom.nid
 WHERE (custom.field = 0 OR custom.field IS NULL)
   ORDER BY node_created DESC

i think the difference is easy to see

merlinofchaos’s picture

In 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.

voxpelli’s picture

Rerolling 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?

merlinofchaos’s picture

Status: Needs review » Fixed

Commited to 2.x and 3.x branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

fonant’s picture

This 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().

fonant’s picture

Status: Closed (fixed) » Needs work
dawehner’s picture

Version: 6.x-2.6 » 6.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new666 bytes

Here is a patch

EPO’s picture

The 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.

merlinofchaos’s picture

After consideration, #11 is separate from this issue, though it's similar. That issue is about arguments, and the patch here is about filters.

merlinofchaos’s picture

Status: Needs review » Fixed

#10 committed to all branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.