Note that there are some explanatory texts on larger screens.

plurals
  1. POcakephp cakedc search plugin - multiple table / multiple query search
    primarykey
    data
    text
    <p>I am having some issues searching from multiple tables. I have a keyword search setup on a cards model which works fine, I also want the keywords to look into a contact model which has a forign key of card_id. I cannot seem to work out how to go about this.</p> <p>The points to look at / with issues are the <code>findByContacts</code> function and:</p> <pre><code>array('Contact.street_suburb' =&gt; 'contacts', 'type' =&gt; 'subquery', 'method' =&gt; 'findByContacts', 'field' =&gt; 'Card.id'), </code></pre> <p>I have initially tried to just get the suburb to search but ideally I would like any of the fields within the contacts model to come up on the card search.</p> <p>Thanks!</p> <p>My code in Card Model is as follows:</p> <pre><code>public $filterArgs = array( array('name' =&gt; 'keyword', 'type' =&gt; 'query', 'method' =&gt; 'filterQuery'), ); public $hasAndBelongsToMany = array('Contact' =&gt; array('with' =&gt; 'Contact')); public function filterQuery($data = array()) { if(empty($data['keyword'])) { // keyword is the name of my search field return array(); } $query = '%'.$data['keyword'].'%'; return array( 'OR' =&gt; array( array('Card.name LIKE' =&gt; $query), array('Property.name LIKE' =&gt; $query), array('Building.name LIKE' =&gt; $query), array('Stage.name LIKE' =&gt; $query), array('Contact.street_suburb' =&gt; 'contacts', 'type' =&gt; 'subquery', 'method' =&gt; 'findByContacts', 'field' =&gt; 'Card.id'), ) ); } // END SEARCH // FIND BY CONACTS - PART OF SEARCH // ------------------------------------------------------------------------------------&gt; public function findByContacts($data = array()) { $this-&gt;Contact-&gt;Behaviors-&gt;attach('Containable', array('autoFields' =&gt; false)); $this-&gt;Contact-&gt;Behaviors-&gt;attach('Search.Searchable'); $query = $this-&gt;Contact-&gt;getQuery('all', array( 'conditions' =&gt; array('Contact.street_suburb' =&gt; $data['contacts']), 'fields' =&gt; array('foreign_key'), 'contain' =&gt; array('Contact') )); return $query; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload