Skip to content
Permalink
Browse files

Fixed typo

  • Loading branch information...
lorenzo committed Jan 2, 2014
1 parent 98df11f commit 5a9f8c0e941296314c8d4f557051506ab2ac648c
Showing with 39 additions and 14 deletions.
  1. +6 −1 Cake/ORM/Query.php
  2. +33 −13 Cake/Test/TestCase/ORM/QueryTest.php
@@ -81,7 +81,8 @@ class Query extends DatabaseQuery {
'conditions' => 1,
'fields' => 1,
'sort' => 1,
'matching' => 1
'matching' => 1,
'queryBuilder' => 1
];
/**
@@ -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];
}
@@ -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',
@@ -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
*

0 comments on commit 5a9f8c0

Please sign in to comment.
You can’t perform that action at this time.