8

I have a query with a 'BETWEEN' operator and I should have some results. Is there any way to show the actual SQL query made ?

Here is my entity query :

    $query = $this->entity_query->get('node');
    $query->condition('type', 'store');
    $query->condition('status', 1);
    if ($lat_min && $lng_min && is_numeric($lat_min) && is_numeric($lng_min) && $lat_max && $lng_max && is_numeric($lat_max) && is_numeric($lng_max)) {
      $query->condition('field_store_geolocation.lat', [$lat_min, $lat_max], 'BETWEEN');
      $query->condition('field_store_geolocation.lng', [$lng_min, $lng_max], 'BETWEEN');
    }
    $nids = $query->execute();

Of course I made sure that my values were the one expected and I also tried with '<', '>' and with no vars but actual values to make sure nothing was wrong there.

I'm using the 'Geolocation Field' module here.

1 Answer 1

20

If you use devel module a simple approach for debugging entity query could be use the debug tag (simply add $query->addTag('debug') to your query). Here an example

$query = $this->entity_query->get('node');
$query->condition('status', NODE_PUBLISHED);
$query->addTag('debug');
$query->execute();

And the result

enter image description here

3
  • Thanks ! For some reason I had tried that and nothing showed up but I could eventually see it by visiting an other page :-) Thanks a lot !
    – pbonnefoi
    Commented Sep 14, 2016 at 8:18
  • 1
    For the anonymous user it's not working, how can I give the access? Commented May 7, 2018 at 10:33
  • 1
    @RajeshVishwakarma enable devel for anonymous
    – Carlos
    Commented Jun 28, 2018 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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