I have a node type A with a field A-Ref, which references nodes of type B. The field A-Ref can have multiple instances, so on node A1, you could refer to B1, B2, B7, etc...

Now I want to make a view with alle the nodes of type A who do not refer to a specific set of nodes of type B. So I want to exclude every node A in which B1, B2 or B3 is referenced. How do I do that? I can't figure it out...

If I use the filters:

+ node type = A
+ A-Ref is not B1
+ A-Ref is not B2
+ A-Ref is not B3

then it won't filter out a node that refer to B2 and B4 for instance. It still includes them, I guess because when it refers to B4, the node gets past the filter (since B4 is not B1, is not B2, is not B3).

The problem seems to be that the filter "is not equal to X" seems to mean "include everything that is not X", whereas I am searching for a way to "exclude everything that is X". On the surface that might seem like two different ways of phrasing the same meaning, but when working with a field with multiple instance, there is a difference. It is the difference between "include every node that has an instance of the field that is not X" and "exclude every node that has an instance of the field that is not X".

I hope that makes sense, and someone out there might be able to point me to a solution in configuring this view. (Or tell me it is impossible, although I find that hard to believe).


Jan_MSK created an issue. See original summary.

MustangGB’s picture

Project: Views » Drupal core
Version: 8.x-3.x-dev » 8.3.x-dev
Component: Miscellaneous » views.module
Lendude’s picture

Since every value for multiple value fields is a new row in SQL, this is exactly what happens. When nodes have multiple references, rows with value B2 get removed, but rows with B4 stay in, so there is your node in your result set (possibly multiple times).

In Views this is hard to do, it's not even easily done in SQL. You would need to group_concat your results on the field you want to filter and then filter the grouped column to not include this when the concatenated values contains any of the values you are looking for.

You can get the grouping done in Views UI (aggregation + the right order of fields + the right type of grouping), but setting the filter up might need some sort of 'combined field filter' tricks (no idea how much trouble you will get into combining this with a grouped field) or a hook_query_alter to get right.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.