Browse Source

Improving translate behavior when used to override columns based on
a single locale

Jose Lorenzo Rodriguez 12 years ago
parent
commit
840af78cc8

+ 2 - 1
src/Model/Behavior/TranslateBehavior.php

@@ -97,8 +97,9 @@ class TranslateBehavior extends Behavior {
 					'_locale' => $locale
 				], $options);
 			}
-			$row->clean();
 
+			$row->clean();
+			unset($row['_i18n']);
 			return $row;
 		});
 	}

+ 28 - 0
tests/TestCase/Model/Behavior/TranslateBehaviorTest.php

@@ -53,5 +53,33 @@ class TranslateBehaviorTest extends TestCase {
 		$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());
+	}
+
 }