0

Neither loadByProperties or entityQuery are case sensitive. How to make it case sensitive? I'm using MySQL as a database but would rather have a portable solution if possible.

With LoadByProperty

$nodes = $this->entityTypeManager()
              ->getStorage('node')
              ->loadByProperties(['field_myfield' => $value]);

With entityQuery

    $entity_ids = \Drupal::entityQuery('node')
        ->condition('field_myfield',$value)
        ->execute();

You can, of course, build your own query as explained in this answer. But my question is specifically about using loadByProperties or entityQuery API.

0
2

It was this long issue thread, they add sensitive case support to entityQuery.

So instead of = operation you can use = BINARY or instead of LIKE you can use LIKE BINARY.
Try this:

$entity_ids = \Drupal::entityQuery('node')
  ->condition('field_myfield',$value, '= BINARY')
  ->execute();
1
  • Thanks! But no luck with loadByProperties? I don't understand why the API provide entityQuery AND loadByProperties to be honest. I like API when their is one obvious way to do things. I will strictly use entityQuery in the future. – gagarine Jun 16 '20 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.