Skip to content

Commit

Permalink
Make ResultSet buffer the statement results.
Browse files Browse the repository at this point in the history
This will allow it to more easily implement serializable interface,
which will be important for caching results.
  • Loading branch information
markstory committed Aug 5, 2013
1 parent 56f36c3 commit 4c2f94b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/Cake/ORM/ResultSet.php
Expand Up @@ -85,6 +85,13 @@ class ResultSet implements Iterator {
*/
protected $_map;

/**
* Results that have been fetched or hydrated into the results.
*
* @var array
*/
protected $_results = [];

/**
* Constructor
*
Expand Down Expand Up @@ -114,7 +121,7 @@ public function toArray() {
* @return array|object
*/
public function current() {
return $this->_groupResult($this->_current);
return $this->_current;
}

/**
Expand Down Expand Up @@ -188,7 +195,11 @@ protected function _calculateAssociationMap() {
*/
protected function _fetchResult() {
if ($this->_lastIndex < $this->_index) {
$this->_current = $this->_statement->fetch('assoc');
$row = $this->_statement->fetch('assoc');
if ($row !== false) {
$row = $this->_groupResult($row);
}
$this->_current = $row;
$this->_lastIndex = $this->_index;
}
}
Expand All @@ -198,10 +209,10 @@ protected function _fetchResult() {
*
* @return array
*/
protected function _groupResult() {
protected function _groupResult($row) {
$defaultAlias = $this->_defaultTable->alias();
$results = [];
foreach ($this->_current as $key => $value) {
foreach ($row as $key => $value) {
$table = $defaultAlias;
$field = $key;

Expand Down

0 comments on commit 4c2f94b

Please sign in to comment.