andWhere() публичный метод

It is important to notice that when calling this function, any previous set of conditions defined for this query will be treated as a single argument for the AND operator. This function will not only operate the most recently defined condition, but all the conditions as a whole. When using an array for defining conditions, creating constraints form each array entry will use the same logic as with the where() function. This means that each array entry will be joined to the other using the AND operator, unless you nest the conditions in the array using other operator. ### Examples: $query->where(['title' => 'Hello World')->andWhere(['author_id' => 1]); Will produce: WHERE title = 'Hello World' AND author_id = 1 $query ->where(['OR' => ['published' => false, 'published is NULL']]) ->andWhere(['author_id' => 1, 'comments_count >' => 10]) Produces: WHERE (published = 0 OR published IS NULL) AND author_id = 1 AND comments_count > 10 $query ->where(['title' => 'Foo']) ->andWhere(function ($exp, $query) { return $exp ->add(['author_id' => 1]) ->or_(['author_id' => 2]); }); Generates the following conditions: WHERE (title = 'Foo') AND (author_id = 1 OR author_id = 2)
См. также: Cake\Database\Query::where()
См. также: Cake\Database\Type
public andWhere ( string | array | Cake\Database\ExpressionInterface | callable $conditions, array $types = [] )
$conditions string | array | Cake\Database\ExpressionInterface | callable The conditions to add with AND.
$types array associative array of type names used to bind values to query
Пример #1
3
 /**
  * Conditionally adds a condition to the passed Query that will make it find
  * records where there is no match with this association.
  *
  * @param \Cake\Database\Query $query The query to modify
  * @param array $options Options array containing the `negateMatch` key.
  * @return void
  */
 protected function _appendNotMatching($query, $options)
 {
     $target = $this->_targetTable;
     if (!empty($options['negateMatch'])) {
         $primaryKey = $query->aliasFields((array) $target->primaryKey(), $this->_name);
         $query->andWhere(function ($exp) use($primaryKey) {
             array_map([$exp, 'isNull'], $primaryKey);
             return $exp;
         });
     }
 }