Permalink
Browse files

Making the internal representaition of containments a simple array, the

idea of returning the ArrayObject so it could be modified from the
outside was a terrible one, was not tested nor documented.
  • Loading branch information...
1 parent 5664ab4 commit e40c150a0e93041ae0239b0f98e44d90f7eb9062 @lorenzo lorenzo committed Jan 30, 2014
Showing with 12 additions and 22 deletions.
  1. +4 −5 src/ORM/EagerLoader.php
  2. +3 −12 src/ORM/Query.php
  3. +5 −5 tests/TestCase/ORM/QueryTest.php
View
@@ -29,7 +29,7 @@ class EagerLoader {
* Nested array describing the association to be fetched
* and the options to apply for each of them, if any
*
- * @var \ArrayObject
+ * @var array
*/
protected $_containments;
@@ -66,7 +66,7 @@ class EagerLoader {
public function contain($associations = null, $override = false) {
if ($this->_containments === null || $override) {
- $this->_containments = new \ArrayObject;
+ $this->_containments = [];
$this->_normalized = null;
}
@@ -85,9 +85,8 @@ public function contain($associations = null, $override = false) {
return;
}
- $old = $this->_containments->getArrayCopy();
- $associations = $this->_reformatContain($associations, $old);
- $this->_containments->exchangeArray($associations);
+ $associations = $this->_reformatContain($associations, $this->_containments);
+ $this->_containments = $associations;
$this->_normalized = null;
}
View
@@ -285,26 +285,17 @@ public function eagerLoader(EagerLoader $instance = null) {
* ]
* ]);
*
- * If called with no arguments, this function will return an ArrayObject with
+ * If called with no arguments, this function will return an array with
* with the list of previously configured associations to be contained in the
- * result. This object can be modified directly as the reference is kept inside
- * the query.
- *
- * The resulting ArrayObject will always have association aliases as keys, and
- * options as values, if no options are passed, the values will be set to an empty
- * array
- *
- * Please note that when modifying directly the containments array, you are
- * required to maintain the structure. That is, association names as keys
- * having array values. Failing to do so will result in an error
+ * result.
*
* If called with an empty first argument and $override is set to true, the
* previous list will be emptied.
*
* @param array|string $associations list of table aliases to be queried
* @param boolean $override whether override previous list with the one passed
* defaults to merging previous list with the new one.
- * @return \ArrayObject|Query
+ * @return array|\Cake\ORM\Query
*/
public function contain($associations = null, $override = false) {
if (empty($associations) && $override) {
@@ -205,7 +205,7 @@ public function testContainDotNotation() {
'clients.orders.stuff',
'clients.companies.categories' => ['conditions' => ['a >' => 1]]
]);
- $expected = new \ArrayObject([
+ $expected = [
'clients' => [
'orders' => [
'stuff' => []
@@ -216,7 +216,7 @@ public function testContainDotNotation() {
]
]
]
- ]);
+ ];
$this->assertEquals($expected, $query->contain());
$query->contain([
'clients.orders' => ['fields' => ['a', 'b']],
@@ -242,14 +242,14 @@ public function testContainClosure() {
'clients' => $builder
]);
- $expected = new \ArrayObject([
+ $expected = [
'clients' => [
'orders' => [
'stuff' => ['fields' => ['a']]
],
'queryBuilder' => $builder
]
- ]);
+ ];
$this->assertEquals($expected, $query->contain());
$query = $this->getMock('\Cake\ORM\Query', ['join'], [$this->connection, $this->table]);
@@ -1011,7 +1011,7 @@ public function testApplyOptions() {
$expected = new QueryExpression($options['having']);
$this->assertEquals($expected, $query->clause('having'));
- $expected = new \ArrayObject(['table_a' => ['table_b' => []]]);
+ $expected = ['table_a' => ['table_b' => []]];
$this->assertEquals($expected, $query->contain());
}

0 comments on commit e40c150

Please sign in to comment.