innerJoinWith() public method

This function will add entries in the contain graph. ### Example: Bring only articles that were tagged with 'cake' $query->innerJoinWith('Tags', function ($q) { return $q->where(['name' => 'cake']); ); This will create the following SQL: SELECT Articles.* FROM articles Articles INNER JOIN tags Tags ON Tags.name = 'cake' INNER JOIN articles_tags ArticlesTags ON ArticlesTags.tag_id = Tags.id AND ArticlesTags.articles_id = Articles.id This function works the same as matching() with the difference that it will select no fields from the association.
See also: Cake\ORM\Query::matching()
public innerJoinWith ( string $assoc, callable $builder = null )
$assoc string The association to join with
$builder callable a function that will receive a pre-made query object that can be used to add custom conditions or selecting some fields
 /**
  * {@inheritDoc}
  *
  * It looks for search-criteria and applies them over the query object. For
  * example, given the criteria below:
  *
  *     "this phrase" -"and not this one"
  *
  * Alters the query object as follow:
  *
  * ```php
  * $query->where([
  *    'indexed_words LIKE' => '%this phrase%',
  *    'indexed_words NOT LIKE' => '%and not this one%'
  * ]);
  * ```
  *
  * The `AND` & `OR` keywords are allowed to create complex conditions. For
  * example:
  *
  *     "this phrase" OR -"and not this one" AND "this"
  *
  * Will produce something like:
  *
  * ```php
  * $query->where(['indexed_words LIKE' => '%this phrase%'])
  *     ->orWhere(['indexed_words NOT LIKE' => '%and not this one%']);
  *     ->andWhere(['indexed_words LIKE' => '%this%']);
  * ```
  */
 public function search($criteria, Query $query)
 {
     $tokens = (array) (new MiniLanguageParser($criteria))->parse();
     if (!empty($tokens)) {
         $query->innerJoinWith('SearchDatasets');
         foreach ($tokens as $token) {
             if ($token->isOperator()) {
                 $query = $this->_scopeOperator($query, $token);
             } else {
                 $query = $this->_scopeWords($query, $token);
             }
         }
     }
     return $query;
 }