title: Cakephp - search by field of different table
body: <p>I have two tables: </p>
  
  <ol>
  <li>evaluation_employees
  Fields: id, username</li>
  <li>evaluation_results
  Fields: id, grade, evaluation_employee_id</li>
  </ol>
  
  <p>In evaluation_results view I need to search the results (using the <a href="http://cakedc.com/downloads/view/cakephp_search_plugin" rel="nofollow">cakephp search plugin</a>) by the employee's username, but in evaluation_results table I have the employee's id(evaluation_employee_id), not the username. I don't know how to make a link between those tables, to make it work.  </p>
  
  <p>Code in my view (evaluation_results/index.ctp):</p>
  
  <pre><code>echo $this-&gt;Form-&gt;create('EvaluationResult', array(
              'url' =&gt; array_merge(array('action' =&gt; 'index'), $this-&gt;params['pass'])
              ));
  echo $this-&gt;Form-&gt;input('username', array('div' =&gt; false, 'empty' =&gt; true)) . '&lt;br/&gt;&lt;br/&gt;';
  echo $this-&gt;Form-&gt;submit(__('Search', true), array('div' =&gt; false));
  echo $this-&gt;Form-&gt;end();
  </code></pre>
  
  <p>Code in my controller (evaluation_results_controller.php):</p>
  
  <pre><code>var $components = array('Search.Prg');
      function index() {
          $this-&gt;Prg-&gt;commonProcess();
          $this-&gt;EvaluationResult-&gt;recursive = 0;
          $this-&gt;paginate = array(
                      'conditions' =&gt; $this-&gt;EvaluationResult-&gt;parseCriteria($this-&gt;passedArgs));
          $this-&gt;set('evaluationResults', $this-&gt;paginate());
      }
  </code></pre>
  
  <p>Code in my model (evaluation_result.php):</p>
  
  <pre><code>public $actsAs = array('Search.Searchable');
  
      //Search fields data description for processing.
      public $filterArgs = array(
          array('name' =&gt; 'EvaluationEmployee.username', 'type' =&gt; 'query', 'method' =&gt; 'filterUsername')
      );
  
      //Method as decalred in $filterArgs to process the free form search.
      public function filterUsername($data, $field = null) {
          if (empty($data['EvaluationEmployee']['username'])) {
              return array();
          }
          $username = '%' . $data['EvaluationEmployee']['username'] . '%';
          return array(
                  $this-&gt;alias . '.EvaluationEmployee.username LIKE' =&gt; $username
              );
      }
  </code></pre>
  
  <p>Please tell me if more info is needed.</p>