Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding docs + exceptions for name translation.

Closes #2367
  • Loading branch information...
commit b5f918765e296245b31cca2270112c4c1311c64e 1 parent a4e3790
Mark Story markstory authored
10 lib/Cake/Model/Behavior/TranslateBehavior.php
View
@@ -368,7 +368,10 @@ public function translateModel($model) {
/**
* Bind translation for fields, optionally with hasMany association for
- * fake field
+ * fake field.
+ *
+ * *Note* You should avoid binding translations that overlap existing model properties.
+ * This can cause un-expected and un-desirable behavior.
*
* @param Model $model instance of model
* @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
@@ -391,6 +394,11 @@ public function bindTranslation($model, $fields, $reset = true) {
$field = $key;
$association = $value;
}
+ if ($field === 'name') {
+ throw new CakeException(
+ __d('cake_dev', 'You cannot bind a translation named "name".')
+ );
+ }
if (array_key_exists($field, $this->settings[$model->alias])) {
unset($this->settings[$model->alias][$field]);
12 lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php
View
@@ -868,4 +868,16 @@ public function testUnbindTranslationInfinteLoop() {
$this->assertFalse($result);
}
+
+/**
+ * Test that an exception is raised when you try to over-write the name attribute.
+ *
+ * @expectedException CakeException
+ * @return void
+ */
+ public function testExceptionOnNameTranslation() {
+ $this->loadFixtures('Translate', 'TranslatedItem');
+ $TestModel = new TranslatedItem();
+ $TestModel->bindTranslation(array('name' => 'name'));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.