Problem/Motivation

The patch from the parent issue works perfectly for ::loadByProperties() as it expects and array of values ​​and will add IN operator, in my case I am facing the same problem using ::entityQuery(),

Steps to reproduce

Being more specific, I'm working with the menu_export module (and PostgreSQL of course) and it has this query:

      $menuLinkEntity = \Drupal::entityQuery('menu_link_content')
        ->accessCheck(FALSE)
        ->condition('uuid', $menu['uuid'])
        ->execute();

Where $menu['uuid'] is an array of values.

The problem with this is that the condition operator is not defined, and when the translateCondition() is executed, it didn't add the operator, which should be "IN", causing this error:

SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "("
LINE 5: WHERE (LOWER("menu_link_content"."uuid")  (LOWER('XXXXX

Proposed resolution

Not sure if it should be a core or module issue, I added a patch that worked for me.

I added the IN operator if $condition['operator'] is empty:

      if (empty($condition['operator'])) {
        $condition['operator'] = 'IN';
      }

I didn't have enough time to add a test, it would be something like this:

    $node1 = $this->drupalCreateNode([
      'type' => 'page',
      'field_first' => '1234',
      'field_second' => 'test_value_1',
    ]);
    $nodes = $this->container->get('entity_type.manager')->getStorage('node')->getQuery()->condition('uuid',[$node1->uuid()])->execute();
    // @todo validate results
CommentFileSizeAuthor
#2 3382082-2.patch799 bytesluisnicg

Comments

luisnicg created an issue. See original summary.

luisnicg’s picture

StatusFileSize
new799 bytes
luisnicg’s picture

Issue summary: View changes
catch’s picture

This should be fixed in the module by adding an explicit IN operator, see https://www.drupal.org/node/3350985

luisnicg’s picture

Thanks for the quick response and feedback on comment #4, I already created the bug in the module.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.