Phalcon datatables adapter where condition not working
<p>I'm using <a href="https://github.com/m1ome/phalcon-datatables" rel="nofollow">phalcon-datatables</a> this is a <a href="https://datatables.net" rel="nofollow">datatables</a> adapter for <a href="https://phalconphp.com/fr/" rel="nofollow">Phalcon PHP</a>.</p>

<p>I have a where condition in my QueryBuilder, e.g :</p>

<pre><code>use \DataTables\DataTable;

class TestController extends \Phalcon\Mvc\Controller {
    public function indexAction() {
        if ($this-&gt;request-&gt;isAjax()) {
          $builder = $this-&gt;modelsManager-&gt;createBuilder()
                          -&gt;columns('id, name, email, age')
                          -&gt;from('Example\Models\User');
                          -&gt;where("age = :age:", array("age" =&gt; 30))

          $dataTables = new DataTable();
          $dataTables-&gt;fromBuilder($builder)-&gt;sendResponse();
        }
    }
}
</code></pre>

<p>But I have a problem when I'm using the global search. The where condition is ignored then it will show me all record in my database with the search condition.</p>

<p>When I'm using the column search it works well.</p>

<p>I think the problem is in this class -> <a href="https://github.com/m1ome/phalcon-datatables/blob/dfa67667557cb8464b4917bfe2856adb3a0380e4/src/Adapters/QueryBuilder.php" rel="nofollow">Github</a> line 21-23</p>

<p>For the global search we need to get all column and this library use orWhere for the global search.</p>

<pre><code>    $this-&gt;bind('global_search', function($column, $search) {
      $this-&gt;builder-&gt;orWhere("{$column} LIKE :key_{$column}:",   ["key_{$column}" =&gt; "%{$search}%"]);
    });
</code></pre>

<p>And the column search use andWhere.</p>

<pre><code>$this-&gt;bind('column_search', function($column, $search) {
  $this-&gt;builder-&gt;andWhere("{$column} LIKE :key_{$column}:", ["key_{$column}" =&gt; "%{$search}%"]);
});
</code></pre>

<p>So I think this is why the column search works with a where condition in the QueryBuilder. And this is why the global search doesn't work.</p>

<p>Do you have any idea to fix this problem inside the library ?</p>

<p><strong>EDIT :</strong></p>

<p>I think I have a solution. I have to put brackets on the orWhere.</p>

<p>But how can I do to make this query with phalcon ?</p>

<pre><code>SELECT *
FROM `users` 
WHERE age = 30 
AND (name like '%d%' 
OR email like '%d%'
OR login like '%d%')
</code></pre>