Skip to content
This repository
Browse code

Adding docs + exceptions for name translation.

Closes #2367
  • Loading branch information...
commit b5f918765e296245b31cca2270112c4c1311c64e 1 parent a4e3790
Mark Story authored December 30, 2011
10  lib/Cake/Model/Behavior/TranslateBehavior.php
@@ -368,7 +368,10 @@ public function translateModel($model) {
368 368
 
369 369
 /**
370 370
  * Bind translation for fields, optionally with hasMany association for
371  
- * fake field
  371
+ * fake field.
  372
+ *
  373
+ * *Note* You should avoid binding translations that overlap existing model properties.
  374
+ * This can cause un-expected and un-desirable behavior.
372 375
  *
373 376
  * @param Model $model instance of model
374 377
  * @param string|array $fields string with field or array(field1, field2=>AssocName, field3)
@@ -391,6 +394,11 @@ public function bindTranslation($model, $fields, $reset = true) {
391 394
 				$field = $key;
392 395
 				$association = $value;
393 396
 			}
  397
+			if ($field === 'name') {
  398
+				throw new CakeException(
  399
+					__d('cake_dev', 'You cannot bind a translation named "name".')
  400
+				);
  401
+			}
394 402
 
395 403
 			if (array_key_exists($field, $this->settings[$model->alias])) {
396 404
 				unset($this->settings[$model->alias][$field]);
12  lib/Cake/Test/Case/Model/Behavior/TranslateBehaviorTest.php
@@ -868,4 +868,16 @@ public function testUnbindTranslationInfinteLoop() {
868 868
 
869 869
 		$this->assertFalse($result);
870 870
 	}
  871
+
  872
+/**
  873
+ * Test that an exception is raised when you try to over-write the name attribute.
  874
+ *
  875
+ * @expectedException CakeException
  876
+ * @return void
  877
+ */
  878
+	public function testExceptionOnNameTranslation() {
  879
+		$this->loadFixtures('Translate', 'TranslatedItem');
  880
+		$TestModel = new TranslatedItem();
  881
+		$TestModel->bindTranslation(array('name' => 'name'));
  882
+	}
871 883
 }

0 notes on commit b5f9187

Please sign in to comment.
Something went wrong with that request. Please try again.