Views OR filter not working for entity reference fields

Created on 29 January 2022, almost 3 years ago
Updated 26 September 2023, about 1 year ago

Problem/Motivation

Filtering records based on multiple values for an entity reference field, or on values of multiple entity reference fields does not work.

Steps to reproduce

1) Add entity reference fields that refer to a taxonomy to a user profile or other entity. Like:
- BOF session first choice
- BOF session second choice
- BOF session third choice
Each field refers to the same taxonomy vocabulary.
2) Create a view for the entities.
3) Add filters to the view using any combination of the above fields.
4) Observe that combinations of OR operators appear to behave as AND operators.

Proposed resolution

Fix the behavior of the operators so they adhere to correct logic for entity reference fields. It appears that the operators behave as expected with non-ER fields, e.g. selecting records with first name (text field) contains 'm' and (/or) last name (text field) contains 's'.

🐛 Bug report
Status

Active

Version

9.5

Component
Views 

Last updated 1 day ago

Created by

🇺🇸United States chuck_theobald

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand quietone

    @chuck_theobald, thanks for reporting the problem.

    I tested this on Drupal 10.1., umami install. I followed the steps in the issue summary and was not able to recreate the problem. Therefor, I am closing this issue. I

    If the config for the problematic view can be provided, change the status to Active and upload the view configuration.

    Thanks.

  • 🇫🇷France federiko_

    Same issue here !
    My buggy view config :

    uuid: 543cbe64-b6ec-4c44-abca-f1548e4a322b
    langcode: fr
    status: true
    dependencies:
      config:
        - user.role.cf
      module:
        - user
    id: entiref_view_or_filter_bug
    label: 'Référents CF'
    module: views
    description: ''
    tag: ''
    base_table: users_field_data
    base_field: uid
    display:
      default:
        id: default
        display_title: Default
        display_plugin: default
        position: 0
        display_options:
          fields:
            name:
              id: name
              table: users_field_data
              field: name
              relationship: none
              group_type: group
              admin_label: ''
              entity_type: user
              entity_field: name
              plugin_id: field
              label: ''
              exclude: false
              alter:
                alter_text: false
                make_link: false
                absolute: false
                word_boundary: false
                ellipsis: false
                strip_tags: false
                trim: false
                html: false
              element_type: ''
              element_class: ''
              element_label_type: ''
              element_label_class: ''
              element_label_colon: true
              element_wrapper_type: ''
              element_wrapper_class: ''
              element_default_classes: true
              empty: ''
              hide_empty: false
              empty_zero: false
              hide_alter_empty: true
              click_sort_column: value
              type: user_name
              settings: {  }
              group_column: value
              group_columns: {  }
              group_rows: true
              delta_limit: 0
              delta_offset: 0
              delta_reversed: false
              delta_first_last: false
              multi_type: separator
              separator: ', '
              field_api_classes: false
          pager:
            type: none
            options:
              offset: 0
          exposed_form:
            type: basic
            options:
              submit_button: Appliquer
              reset_button: false
              reset_button_label: Réinitialiser
              exposed_sorts_label: 'Trier par'
              expose_sort_order: true
              sort_asc_label: Asc
              sort_desc_label: Desc
          access:
            type: perm
            options:
              perm: 'access user profiles'
          cache:
            type: tag
            options: {  }
          empty: {  }
          sorts:
            name:
              id: name
              table: users_field_data
              field: name
              relationship: none
              group_type: group
              admin_label: ''
              entity_type: user
              entity_field: name
              plugin_id: standard
              order: ASC
              expose:
                label: ''
                field_identifier: ''
              exposed: false
          arguments: {  }
          filters:
            status:
              id: status
              table: users_field_data
              field: status
              entity_type: user
              entity_field: status
              plugin_id: boolean
              value: '1'
              group: 1
              expose:
                operator: ''
                operator_limit_selection: false
                operator_list: {  }
            field_previous_roles_target_id:
              id: field_previous_roles_target_id
              table: user__field_previous_roles
              field: field_previous_roles_target_id
              relationship: none
              group_type: group
              admin_label: ''
              plugin_id: string
              operator: '='
              value: cf
              group: 2
              exposed: false
              expose:
                operator_id: ''
                label: ''
                description: ''
                use_operator: false
                operator: ''
                operator_limit_selection: false
                operator_list: {  }
                identifier: ''
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                placeholder: ''
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
            roles_target_id:
              id: roles_target_id
              table: user__roles
              field: roles_target_id
              relationship: none
              group_type: group
              admin_label: ''
              entity_type: user
              entity_field: roles
              plugin_id: user_roles
              operator: or
              value:
                cf: cf
              group: 2
              exposed: false
              expose:
                operator_id: ''
                label: ''
                description: ''
                use_operator: false
                operator: ''
                operator_limit_selection: false
                operator_list: {  }
                identifier: ''
                required: false
                remember: false
                multiple: false
                remember_roles:
                  authenticated: authenticated
                reduce: false
              is_grouped: false
              group_info:
                label: ''
                description: ''
                identifier: ''
                optional: true
                widget: select
                multiple: false
                remember: false
                default_group: All
                default_group_multiple: {  }
                group_items: {  }
              reduce_duplicates: false
          filter_groups:
            operator: AND
            groups:
              1: AND
              2: OR
          style:
            type: default
            options:
              grouping: {  }
              row_class: ''
              default_row_class: true
              uses_fields: false
          row:
            type: fields
            options:
              default_field_elements: true
              inline: {  }
              separator: ''
              hide_empty: false
          query:
            type: views_query
            options:
              query_comment: ''
              disable_sql_rewrite: false
              distinct: false
              replica: false
              query_tags: {  }
          relationships: {  }
          header: {  }
          footer: {  }
          display_extenders: {  }
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_content'
            - 'languages:language_interface'
            - user.permissions
          tags: {  }
      manager_cf_users:
        id: manager_cf_users
        display_title: 'Entity Reference for CF users'
        display_plugin: entity_reference
        position: 1
        display_options:
          style:
            type: entity_reference
            options:
              search_fields:
                name: name
          display_description: ''
          display_extenders: {  }
        cache_metadata:
          max-age: -1
          contexts:
            - 'languages:language_content'
            - 'languages:language_interface'
            - user.permissions
          tags: {  }
    
  • Status changed to Active about 1 year ago
Production build 0.71.5 2024