I have a good solution that you can copy/paste your query string directly in "SQL" section in Phpmyadmin and debug your query ( I often use this method when I struggle with query)


    $querystring=$query->__toString();
    $querystring=str_replace("{",'',$querystring);
    $querystring=str_replace("}",'',$querystring);
    foreach($query->getArguments() as $key=> $item){

        if(!$item) {
            $item = 'NULL';
        }
        $querystring=str_replace($key.')',$item.')',$querystring);
    }
    dpm($querystring);
    
I hope this be usful for other guys.