I'm having a problem getting views to properly display content when an image field is empty.
I've created a new content type called Articles. Within Articles there is a new image field called teaser_image.
I've created a view that displays all Articles that also have an image uploaded into the teaser_image field. This works as it should when the content: teaser_image is set to True. So far so good.
Now I want to create another view that does the opposite, displaying only those Articles without a teaser_image. But setting the content: teaser_image to False returns nothing at all.
I've tried to do this with an argument as well, but Views seems to be having a problem in failing to recognize NULL.
Is there some way around this or has the issue been corrected in the dev release?
Comments
Comment #1
dawehnerI think the problem is the filter implementation of the cck field or not?
Comment #2
hawkdrupal commentedI'm still fine-tuning my understanding of how Views 2 works, but maybe I can shed light...
Does the field teaser_image exist even in a node that does not have anything in the field? Or, does the field NOT exist (vs. exist but with no data)? If the field does not exist in a node when it hasn't yet been used in that node, your problem is likely the same as mine.
My need is to show a node's comment with the node. To not show spam and "bad" comments, a filter checks to be sure the comment is Published (vs. Unpublished) as set by the admin/moderator when reviewing new comments. (I posted about this here: http://drupal.org/node/659964)
Like most filters, the node comment's status is included/excluded via a WHERE clause. The huge problem is that a False WHERE means the entire NODE is excluded. What should be excluded is only the field being checked -- a comment in my case, an image in your case.
The general problem is that a WHERE meant to check some part of a node -- Published comment, or teaser_image -- controls the node itself rather than the field being checked.
Apparently this problem arises because a Views filter can't use OR so it can't do certain types of WHERE evaluations.
The desired result is to check a field expression and return True/False as desired -- OR if the field/value does not exist/is null, return True/False as specified -- essentially a compound filter resulting in a compound WHERE clause.
It seems to me that your need and mine is a common scenario, but in Views 2 I haven't found a way to do it.
For node comments I have to either add a fake Published comment to every node that lacks a real comment, or to risk spammers getting their Unpublished comments included in views during the gap between then the comment is posted and the admin notices and deletes it.
Perhaps in your situation you can check for an image in both views, but for the "no image" view use WHERE NOT data rather than WHERE no-data? (Somehow...)
Comment #3
dawehner
You can do this with the views_or module.The desired result is to check a field expression and return True/False as desired -- OR if the field/value does not exist/is null, return True/False as specified -- essentially a compound filter resulting in a compound WHERE clause.
I think thats everything you need. If you have installed the module you get 3 new filters:
So if you want to have where firstexpresssion OR secondexpression you do it the following way:
Comment #4
les limHold on - you're all over-thinking this. Dmaddox's problem is that the filter he's using doesn't check what he thinks it does. Imagefield doesn't provide a views filter called "Content: Image". What it provides is "Content: Image - list". That is, you can filter for whether the "List this item in the node display" property is true/false for the uploaded file. That's totally the wrong filter for this scenario.
Dmaddox, what you want to do instead is add the "Content: Image" relationship to the view. This will provide a new set of filter possibilities to your view. Select the "File: File ID" filter, make sure it's set to use the Image relationship, then change the operator to "Is empty (NULL)". Remove the "list" filter if you haven't already. This should do exactly what you want.
Comment #5
les lim