Theme colour switcher

Drupal views doesn't show content if entity reference field relationship is empty

Recently I discovered an odd Drupal Views bug. While testing a view I realized that content it should have shown was missing from one display. After a lot of testing, it turned out it was due to two relationships to content in entity reference fields on the content type my view displays. These fields were empty in the missing nodes. Removing the relationships or adding content to those fields made the content show up in the view.

Obviously, I don't want to have to fill those fields out for every piece of content, and I needed the relationships. Normally, this shouldn't be a problem. Views relationships have a "require this relationship" checkmark which will hide any content that does not have the relationship, but this was not checked for either of the problem relationships. Relationships tell the view about extended data it can or cannot show; they don't in themselves determine whether content shows up unless you select that checkmark.

Eventually I discovered that checking "Disable SQL rewriting" in the view Advanced tab, Query settings fixed the problem. This can be a double-edged sword because this also disables any node access checks, meaning users can see content they're not supposed to if you don't configure the view properly. In my case, this view has access validation on a contextual filter; or this could also be done using the view Access settings.

As the issue affected only one display of the view, it could have been due to some other factor, but a lot of testing got me nowhere and this fix does the job. It appears to be a Drupal bug, but I couldn't find mention of it on; I did find one post on Stackexchange about it, but from 6 years ago.


Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.