Skip to content

Commit

Permalink
Quick fix for #4650
Browse files Browse the repository at this point in the history
Buffering results at the end and not at the beginning prevents result
formatters being invoked everytime the iterator is reset
  • Loading branch information
lorenzo committed Sep 22, 2014
1 parent 29602a9 commit 732556f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Datasource/QueryTrait.php
Expand Up @@ -413,6 +413,10 @@ protected function _decorateResults($result) {
$result = new $decorator($result);
}

if ($this->bufferResults()) {
$result = $result->buffered();
}

return $result;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/Model/Behavior/TranslateBehaviorTest.php
Expand Up @@ -743,4 +743,20 @@ public function testSaveMultipleNewTranslations() {
$this->assertEquals('Titre', $translations['fre']->get('title'));
}

/**
* Tests that iterating a resultset twice when using the translations finder
* will not cause any errors nor information loss
*
* @return void
*/
public function testUseCountInFindTranslations() {
$table = TableRegistry::get('Articles');
$table->addBehavior('Translate', ['fields' => ['title', 'body']]);
$articles = $results = $table->find('translations');
$all = $articles->all();
$this->assertCount(3, $all);
$article = $all->first();
$this->assertNotEmpty($article->get('_translations'));
}

}

0 comments on commit 732556f

Please sign in to comment.