Skip to content

Commit

Permalink
Forgot to add a note about using closures in where()
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Feb 3, 2013
1 parent 541e79a commit 9ca2778
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/Cake/Model/Datasource/Database/Query.php
Expand Up @@ -638,6 +638,27 @@ protected function _buildJoinPart($parts) {
*
* Other Query objects that be used as conditions for any field.
*
* ## Adding conditions in multiple steps:
*
* You can use callable functions to construct complex expressions, functions
* receive as first argument a new QueryExpression object and this query instance
* as second argument. Functions must return an expression object, that will be
* added the list of conditions for the query using th AND operator
*
* {{
* $query
* ->where(['title !=' => 'Hello World'])
* ->where(function($exp, $query) {
* $or = $exp->or_(['id' => 1]);
$and = $exp->and_(['id >' => 2, 'id <' => 10]);
return $or->add($and);
* });
* }}
*
* * The previous example produces:
*
* ``WHERE title != 'Hello World' AND (id = 1 OR (id > 2 AND id < 10))``
*
* ## Conditions as strings:
*
* {{
Expand Down

0 comments on commit 9ca2778

Please sign in to comment.