Permalink
Browse files

Improving translate behavior when used to override columns based on

a single locale
  • Loading branch information...
1 parent f5593ed commit 840af78cc8196c014cb14268c4b4ec0339bed191 @lorenzo lorenzo committed Jan 23, 2014
View
3 src/Model/Behavior/TranslateBehavior.php
@@ -97,8 +97,9 @@ protected function _rowMapper($results, $locale) {
'_locale' => $locale
], $options);
}
- $row->clean();
+ $row->clean();
+ unset($row['_i18n']);
return $row;
});
}
View
28 tests/TestCase/Model/Behavior/TranslateBehaviorTest.php
@@ -53,5 +53,33 @@ public function testFindSingleLocale() {
$this->assertSame($expected, $results);
}
+/**
+ * Tests that overriding fields with the translate behavior works when
+ * using conditions and that all other columns are preserved
+ *
+ * @return void
+ */
+ public function testFindSingleLocaleWithConditions() {
+ $table = TableRegistry::get('Articles');
+ $table->addBehavior('Translate');
+ $table->locale('eng');
+ $results = $table->find()
+ ->where(['id' => 2])
+ ->all();
+
+ $this->assertCount(1, $results);
+ $row = $results->first();
+
+ $expected = [
+ 'id' => 2,
+ 'title' => 'Title #2',
+ 'body' => 'Content #2',
+ 'author_id' => 3,
+ 'published' => 'Y',
+ '_locale' => 'eng'
+ ];
+ $this->assertEquals($expected, $row->toArray());
+ }
+
}

0 comments on commit 840af78

Please sign in to comment.