Skip to content

Commit

Permalink
Simplify constructor logic.
Browse files Browse the repository at this point in the history
Chaining through multiple objects makes mocking and testing harder.
Moving method calls out of the constructor makes the ResultSet simpler to
work with. This will be more important as serialize features are
implemented.
  • Loading branch information
markstory committed Aug 4, 2013
1 parent f72d2b2 commit 62e68d0
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lib/Cake/ORM/ResultSet.php
Expand Up @@ -70,13 +70,6 @@ class ResultSet implements Iterator {
*/
protected $_defaultTable;

/**
* Default table alias
*
* @var string
*/
protected $_defaultAlias;

/**
* List of associations that should be eager loaded
*
Expand All @@ -103,7 +96,6 @@ public function __construct($query, $statement) {
$this->_query = $query;
$this->_statement = $statement;
$this->_defaultTable = $this->_query->repository();
$this->_defaultAlias = $this->_defaultTable->alias();
$this->_calculateAssociationMap();
}

Expand Down Expand Up @@ -207,9 +199,10 @@ protected function _fetchResult() {
* @return array
*/
protected function _groupResult() {
$defaultAlias = $this->_defaultTable->alias();
$results = [];
foreach ($this->_current as $key => $value) {
$table = $this->_defaultAlias;
$table = $defaultAlias;
$field = $key;

if (empty($this->_map[$key])) {
Expand All @@ -226,9 +219,9 @@ protected function _groupResult() {
$results[$table][$field] = $value;
}

$results[$this->_defaultAlias] = $this->_castValues(
$results[$defaultAlias] = $this->_castValues(
$this->_defaultTable,
$results[$this->_defaultAlias]
$results[$defaultAlias]
);

foreach (array_reverse($this->_associationMap) as $alias => $assoc) {
Expand All @@ -239,7 +232,7 @@ protected function _groupResult() {
$results = $assoc->transformRow($results);
}

return $results[$this->_defaultAlias];
return $results[$defaultAlias];
}

/**
Expand Down Expand Up @@ -269,4 +262,5 @@ protected function _castValues($table, $values) {

return $values;
}

}

0 comments on commit 62e68d0

Please sign in to comment.