Skip to content
Permalink
Browse files

Quick fix for #4650

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 732556f25543946cb6713e8a44e7c1a48c77580d
Showing with 20 additions and 0 deletions.
  1. +4 −0 src/Datasource/QueryTrait.php
  2. +16 −0 tests/TestCase/Model/Behavior/TranslateBehaviorTest.php
@@ -413,6 +413,10 @@ protected function _decorateResults($result) {
$result = new $decorator($result);
}
if ($this->bufferResults()) {
$result = $result->buffered();
}
return $result;
}
@@ -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.
You can’t perform that action at this time.