Skip to content

Commit

Permalink
Fixed typo
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 2, 2014
1 parent 98df11f commit 5a9f8c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Cake/ORM/Query.php
Expand Up @@ -81,7 +81,8 @@ class Query extends DatabaseQuery {
'conditions' => 1,
'fields' => 1,
'sort' => 1,
'matching' => 1
'matching' => 1,
'queryBuilder' => 1
];

/**
Expand Down Expand Up @@ -343,6 +344,10 @@ protected function _reformatContain($associations, $original) {
$options = $this->_reformatContain($options, []);
}

if ($options instanceof \Closure) {
$options = ['queryBuilder' => $options];
}

$pointer += [$table => []];
$pointer[$table] = $options + $pointer[$table];
}
Expand Down
46 changes: 33 additions & 13 deletions Cake/Test/TestCase/ORM/QueryTest.php
Expand Up @@ -198,23 +198,11 @@ public function testContainToJoinsOneLevel() {

/**
* Tests setting containments using dot notation, additionaly proves that options
* are not overwritten whn combining dot notation and array notation
* are not overwritten when combining dot notation and array notation
*
* @return void
*/
public function testContainDotNotation() {
$contains = [
'clients' => [
'orders' => [
'orderTypes',
'stuff' => ['stuffTypes']
],
'companies' => [
'foreignKey' => 'organization_id',
'categories'
]
]
];
$query = $this->getMock('\Cake\ORM\Query', ['join'], [$this->connection, $this->table]);
$query->contain([
'clients.orders.stuff',
Expand Down Expand Up @@ -243,6 +231,38 @@ public function testContainDotNotation() {
$this->assertEquals($expected, $query->contain());
}

/**
* Tests that it is possible to pass a function as the array value for contain
*
* @return void
*/
public function testContainClosure() {
$builder = function($query) {
};
$query = $this->getMock('\Cake\ORM\Query', ['join'], [$this->connection, $this->table]);
$query->contain([
'clients.orders.stuff' => ['fields' => ['a']],
'clients' => $builder
]);

$expected = new \ArrayObject([
'clients' => [
'orders' => [
'stuff' => ['fields' => ['a']]
],
'queryBuilder' => $builder
]
]);
$this->assertEquals($expected, $query->contain());

$query = $this->getMock('\Cake\ORM\Query', ['join'], [$this->connection, $this->table]);
$query->contain([
'clients.orders.stuff' => ['fields' => ['a']],
'clients' => ['queryBuilder' => $builder]
]);
$this->assertEquals($expected, $query->contain());
}

/**
* Test that fields for contained models are aliased and added to the select clause
*
Expand Down

0 comments on commit 5a9f8c0

Please sign in to comment.