Allow boolean filters to treat NULL as FALSE

voxpelli - July 2, 2009 - 11:40
Project:Views
Version:6.x-2.6
Component:Views Data
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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.

AttachmentSize
views_filter_boolean_null_fix.patch3.58 KB

#1

dereine - July 2, 2009 - 19:53

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.

#2

voxpelli - July 2, 2009 - 19:58

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

#3

dereine - July 2, 2009 - 20:08

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

#4

merlinofchaos - July 2, 2009 - 21:42

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.

#5

voxpelli - July 3, 2009 - 15:30

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?

AttachmentSize
views_filter_boolean_null_fix_issue_508124_5.patch 3.58 KB

#6

merlinofchaos - September 15, 2009 - 16:19
Status:needs review» fixed

Commited to 2.x and 3.x branches.

#7

System Message - September 29, 2009 - 16:20
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.