Score:-2

View Filters' OR operator not applied

br flag

I created a content view that has a filter group using the AND operator that is ANDed with another filter group using the OR operator (see image below)

enter image description here

However, the query constructed is all AND operators and groups aren't even applied. Here is the WHERE clause of the query:

WHERE 
(
  (
    // Content: Type (= On-demand)
    node__field_format.field_format_target_id = '29'
  )
) 
AND 
(
  (
    (
      // Content: Published (= Yes)
      "node_field_data"."status" = '1'
    )
    AND 
    (
      // Content: Content type (in Event, Training)
      "node_field_data"."type" IN ('event', 'training_session')
    )
  ) 
  AND
  (
    (
      // (field_date_and_location: Paragraph) Paragraph: Date Range (>= + 0 minutes)
      DATE_FORMAT((paragraphs_item_field_data_node__field_date_and_location__paragraph__field_date_range.field_date_range_value + INTERVAL -21600 SECOND), '%Y-%m-%d\T%H:%i:%s') >= DATE_FORMAT(('2021-10-19T18:53:48' + INTERVAL -21600 SECOND), '%Y-%m-%d\T%H:%i:%s')
    )
  )
)

This query isn't even remotely close to what I have it configured as... By my configurations, I would expect the WHERE clause to be

WHERE 
(
  (
    // Content: Published (= Yes)
    "node_field_data"."status" = '1'
  )
  AND 
  (
    // Content: Content type (in Event, Training)
    "node_field_data"."type" IN ('event', 'training_session')
  )
) 
AND 
(
  (
    // Content: Type (= On-demand)
    node__field_format.field_format_target_id = '29'
  ) 
  OR
  (
    // (field_date_and_location: Paragraph) Paragraph: Date Range (>= + 0 minutes)
    DATE_FORMAT((paragraphs_item_field_data_node__field_date_and_location__paragraph__field_date_range.field_date_range_value + INTERVAL -21600 SECOND), '%Y-%m-%d\T%H:%i:%s') >= DATE_FORMAT(('2021-10-19T18:53:48' + INTERVAL -21600 SECOND), '%Y-%m-%d\T%H:%i:%s')
  )
)

What's the issue with my configurations? I feel this should be pretty a straightforward implementation but the degree to which the query is incorrect seems off..

Score:0
br flag

It appears that Drupal has a bug in their code. The content type we are displaying has a couple of Types which is a taxonomy term. If a record has an On Demand taxonomy type, it does not have a Date. However, when displaying this list we need to display all content with a date in the future OR has the 'On Demand' taxonomy type.

In addition, we have an exposed filter that allows a user to filter by this taxonomy term type. Therefore, there are two separate filters on the same field, one is exposed the other is not.

In the first condition group, there exists an exposed filter condition called Has Taxonomy Term that is looking at the Topic taxonomy term.

In the second condition group, there exists a non-exposed filter condition called Content: Type that is also looking at the Topic taxonomy term.

However, when Drupal builds up this where clause. it puts the Content Type == On Demand condition into the condition group where the similar exposed filter exists.

You MUST fix this in hook_views_query_alter. I have reported this as a bug on Drupal.org

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.